ClementBera uploaded a new version of BytecodeSets to project VM Maker:
http://source.squeak.org/VMMaker/BytecodeSets.spur-cb.66.mcz
==================== Summary ====================
Name: BytecodeSets.spur-cb.66
Author: cb
Time: 19 January 2017, 5:52:17.032116 pm
UUID: adcb4362-6dd8-49a5-9ca0-156b185b00ea
Ancestors: BytecodeSets.spur-eem.65
Added support for branchIfInstanceOf: decoding
=============== Diff against BytecodeSets.spur-eem.65 ===============
Item was added:
+ ----- Method: InstructionClient>>branchIfInstanceOf:distance: (in category '*BytecodeSets-instruction decoding') -----
+ branchIfInstanceOf: literal distance: distance
+ "If the object on top of stack has the type -or one of the type- present in the literal (the literal is a behavior or an array of behavior), then pop it. Else jumps by the distance."
+ !
Item was added:
+ ----- Method: InstructionPrinter>>branchIfInstanceOf:distance: (in category '*BytecodeSets-SistaV1-decoding') -----
+ branchIfInstanceOf: behaviorOrArrayOfBehavior distance: distance
+ "If the object on top of stack has the type -or one of the type- present in the literal
+ (the literal is a behavior or an array of behavior), then pop it. Else jumps by the distance."
+ self print: 'branchIfInstanceOf: ', behaviorOrArrayOfBehavior printString, ' distance: ', distance printString!
Item was changed:
----- Method: InstructionStream>>interpretNext3ByteSistaV1Instruction:for:extA:extB:startPC: (in category '*BytecodeSets-SistaV1-decoding') -----
interpretNext3ByteSistaV1Instruction: bytecode for: client extA: extA extB: extB startPC: startPC
"Send to the argument, client, a message that specifies the next instruction.
This method handles the three-byte codes.
For a table of the bytecode set, see EncoderForSistaV1's class comment."
| method byte2 byte3 literal |
method := self method.
byte2 := method at: pc.
byte3 := method at: pc + 1.
pc := pc + 2.
"we search the bytecodes by what we expect to be the static frequency."
bytecode = 248 ifTrue:
[byte3 >= 128 ifTrue:
[^client callInlinePrimitive: byte2 + (byte3 - 128 bitShift: 8)].
^client callPrimitive: byte2 + (byte3 bitShift: 8)].
"* 249 11111001 xxxxxxxx siyyyyyy push Closure Compiled block literal index xxxxxxxx (+ Extend A * 256) numCopied yyyyyy receiverOnStack: s = 1 ignoreOuterContext: i = 1"
bytecode = 249 ifTrue:
[literal := method literalAt: (extA bitShift: 8) + byte2 + 1.
^client pushFullClosure: literal numCopied: (byte3 bitAnd: 16r3F)].
bytecode = 250 ifTrue:
["** 250 11111010 eeiiikkk jjjjjjjj Push Closure Num Copied iii (+ExtA//16*8) Num Args kkk (+ ExtA\\16*8) BlockSize jjjjjjjj (+ExtB*256). ee = num extensions"
^client
pushClosureCopyNumCopiedValues: ((byte2 bitShift: -3) bitAnd: 7) + (extA // 16 bitShift: 3)
numArgs: (byte2 bitAnd: 7) + (extA \\ 16 bitShift: 3)
blockSize: byte3 + (extB bitShift: 8)].
bytecode = 251 ifTrue:
[^client pushRemoteTemp: byte2 inVectorAt: byte3].
bytecode = 252 ifTrue:
[^client storeIntoRemoteTemp: byte2 inVectorAt: byte3].
bytecode = 253 ifTrue:
[^client popIntoRemoteTemp: byte2 inVectorAt: byte3].
"** 254 11111110 kkkkkkkk jjjjjjjj branch If Not Instance Of Behavior/Array Of Behavior kkkkkkkk (+ Extend A * 256, where Extend A >= 0) distance jjjjjjjj (+ Extend B * 256, where Extend B >= 0)"
bytecode = 254 ifTrue:
+ [extB < 0 ifTrue: [client branchIfInstanceOf: literal distance: (extB + 128 bitShift: 8) + byte3].
+ ^ client branchIfNotInstanceOf: literal distance: (extB bitShift: 8) + byte3 ].
- [^ client branchIfNotInstanceOf: literal distance: (extB bitShift: 8) + byte3 ].
^self unusedBytecode: client at: startPC!
Item was changed:
----- Method: StackDepthFinder>>branchIfNotInstanceOf:distance: (in category '*BytecodeSets-SistaV1-decoding') -----
+ branchIfNotInstanceOf: behaviorOrArrayOfBehavior distance: delta
+ self drop.
+ self doJump: delta!
- branchIfNotInstanceOf: behaviorOrArrayOfBehavior distance: anInteger
- self drop!
ClementBera uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-cb.2105.mcz
==================== Summary ====================
Name: VMMaker.oscog-cb.2105
Author: cb
Time: 19 January 2017, 12:19:42.246677 pm
UUID: 1f5ef635-cb7b-48c2-be74-4345d39c620f
Ancestors: VMMaker.oscog-cb.2104
Set deadCode to true in trap bytecode to avoid generating merge machne code that is never reached.
Something is fishy in debugStackPointers in the SistaVM. It fails multiple assertion. I believe it's related tobranchIfInstanceOf bytecodes
=============== Diff against VMMaker.oscog-cb.2104 ===============
Item was changed:
----- Method: SistaCogit>>genUnconditionalTrapBytecode (in category 'bytecode generators') -----
genUnconditionalTrapBytecode
"SistaV1: * 217 Trap"
self ssFlushTo: simStackPtr.
self CallRT: ceTrapTrampoline.
self annotateBytecode: self Label.
+ deadCode := true.
^0!
I've reproduced the crash in squeak.stack.spur Win32 with latest vm sources
(SHA aa11221d9ebb5d60b0b88a2f1f8e27f19909d718)
This crashing VM is compiled with gcc via ./mvm -f
The Win64 version passes correctly. But it is compiled with clang by
default.
The Win32 compiled with clang also passes correctly for me.
The test is translated in pure Alien for purpose of testing on Squeak 5.0
(see instructions below).
--------------------------------------------------------------
from cygwin (or cygwin64) shell:
$ i686-w64-mingw32-gcc --version
i686-w64-mingw32-gcc (GCC) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ i686-w64-mingw32-clang --version
clang version 3.8.1 (tags/RELEASE_381/final)
Target: i686-w64-windows-gnu
Thread model: posix
InstalledDir: /usr/bin
$ x86_64-w64-mingw32-clang --version
clang version 3.8.1 (tags/RELEASE_381/final)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: /usr/bin
--------------------------------------------------------------
$ cd build.win32x86/squeak.stack.spur
$ ./mvm -f -- CC=i686-w64-mingw32-clang
or for 64 bits:
$ cd build.win64x64/squeak.stack.spur
$ ./mvm -f
--------------------------------------------------------------
$ cat >test.c << END
#include "stdint.h"
int8_t test(int8_t(*function)(int8_t), int8_t value) {
return function(value);
}
END
$ i686-w64-mingw32-clang -c test.c
$ i686-w64-mingw32-clang -shared -o build/vm/test.dll test.o
$ build/vm/Squeak.exe
--------------------------------------------------------------
then from Smalltalk image with Alien properly loaded (Alien-eem.39):
Callback>>int8RetInt8: callbackContext regs: regsAlien
<signature: #(int8 (*)(int8))>
^callbackContext wordResult:
(block value: (regsAlien signedCharAt: 1) asInteger)
(for now, above method must be compiled in each Callback subclass since we
do not ask Pragma to scan superclass for signatures)
TestCase subclass: #AlienCallbackSunit
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Alien-CoreTest'
AlienCallbackSunit>>createCallback
^Callback
signature: #(int8 (*)(int8))
block: [ :value | value ]
AlienCallbackSunit>>primCall: aCallback int8: aNumber
| r |
(Alien lookup: 'test' inLibrary: 'test.dll')
primFFICallResult: (r := Alien new: 1)
with: aCallback thunk
with: aNumber.
^(r signedCharAt: 1) asInteger
AlienCallbackSunit>>test
self
assert: (self primCall: self createCallback int8: 0)
equals: 0
AlienCallbackSunit new test.
2017-01-14 2:53 GMT+01:00 Eliot Miranda <eliot.miranda(a)gmail.com>:
> Hi Aliaksei,
>
> On Jan 13, 2017, at 10:27 AM, Aliaksei Syrel <alex.syrel(a)gmail.com> wrote:
>
> Hi
>
> The following code crashes windows spur32 VM without crash.dmp:
> (crashes not only in case of int8, but ulong, int16/32 and so on...)
>
> Callback instantiation:
>
> createCallback
>> ^ FFICallback
>> signature: #(int8 (int8))
>> block: [ :value | value ]
>
>
> C function:
>
> int8_t test(int8_t(*function)(int8_t), int8_t value) {
>> return function(value);
>> }
>
>
> FFI call:
>
> primCall: aCallback int8: aNumber
>> ^ self ffiCall: #(int8 test(FFICallback aCallback, int8 aNumber))
>
>
> Test case:
>
> test
>> self
>> assert: (self primCall: self createCallback int8: 0)
>> equals: 0
>
>
>
> Windows 10.
> VM from today:
> http://files.pharo.org/vm/pharo-spur32/win/pharo-win-
> i386-201701130756-83c0ef1.zip
> Image 60343:
> http://files.pharo.org/image/60/60343.zip
>
> P.S. what is the best place to report FFI / Alien issues?
>
>
> vm-dev
>
> P.P.S Iceberg works
>
> Cheers,
> Alex
>
>