[Vm-dev] Is there a way to get the simulated/possible machine code of a CompiledMethod ?

Mariano Martinez Peck marianopeck at gmail.com
Mon Apr 18 00:03:19 UTC 2011


On Sun, Apr 17, 2011 at 3:24 AM, Eliot Miranda <eliot.miranda at gmail.com>wrote:

>
>
>
> On Sat, Apr 16, 2011 at 4:50 PM, Mariano Martinez Peck <
> marianopeck at gmail.com> wrote:
>
>>
>> Hi Eliot. For learning purposes, I would LOVE to be able to do something
>> like:
>>
>>
>> (StackInterpreter >> #lookupMethodInClass:) simulatedMachineCode
>>
>
> Its easy to add a primitive to get the code.  What's problematic is
> decorating that code.  Decorating it involves knowing the names for the
> variables whose addresses appear in the machine code, and that's tedious to
> write.  The best way I know of getting the code right now is to use the
> VMMaker and Bochs plugin and the interface that allows one to supply a
> method in the current image to the simulator and have it translate it as if
> it were in the image being simulated (if that makes sense).  The
> VMMaker/Bochs plugin pair decorates the code beautifully. e.g.
>
> Cogit chooseCogitClass genAndDis: (Point >> #setX:setY:)
>
>
Hi Eliot. I don't pretend the decorating. A minimal, approximated
representation is more than enough.
 I tried but first error was because #primitiveErrorTable is not implemented
in SmalltalkImage and:


CurrentImageCoInterpreterFacade >> initializeObjectMap
    objectMap := IdentityDictionary new.
    { nil. false. true. Smalltalk primitiveErrorTable. Float } do:
        [:o| self oopForObject: o]


So...I implemented. But then there where several erros because "memory" was
a ByteArray and not a Bitmap, and several messages were implemented in
BitMap, like #unsignedLongAt: #unsignedByteAt:, etc.

I tried with latest code commited.

Thanks in advance

Mariano


generates the following if you choose SimpleStackBasedCogit:
>
> E68
>  objhdr: 1003
> nArgs: 2 type: 2
>  blksiz: C0
> method: 100040
> mthhdr: 4100801
>  selctr: 100048=setX:setY:
> blkentry: 0
> stackCheckOffset: 53/EBB
>  00000e80: xorl %edx, %edx : 31 D2
> 00000e82: call .+0xfffffb61 (0x000009e8=ceMethodAbort) : E8 61 FB FF FF
>  00000e87: nop  : 90
> entry:
> 00000e88: movl %edx, %eax : 89 D0
>  00000e8a: andl $0x00000001, %eax : 83 E0 01
> 00000e8d: jnz .+0x00000010 (0x00000e9f=setX:setY:@37) : 75 10
>  00000e8f: movl %ds:(%edx), %eax : 8B 02
> 00000e91: shrl $0x0a, %eax : C1 E8 0A
>  00000e94: andl $0x0000007c, %eax : 83 E0 7C
> 00000e97: jnz .+0x00000006 (0x00000e9f=setX:setY:@37) : 75 06
>  00000e99: movl %ds:0xfffffffc(%edx), %eax : 8B 42 FC
> 00000e9c: andl $0xfffffffc, %eax : 83 E0 FC
>  00000e9f: cmpl %ecx, %eax : 39 C8
> 00000ea1: jnz .+0xffffffdf (0x00000e82=setX:setY:@1A) : 75 DF
>  noCheckEntry:
> 00000ea3: pushl %ebp : 55
> 00000ea4: movl %esp, %ebp : 89 E5
>  00000ea6: pushl $0x00000e68=setX:setY:@0 : 68 68 0E 00 00
> IsAbsPCReference:
>  00000eab: movl $0x00100000=nil, %ebx : BB 00 00 10 00
> 00000eb0: pushl %ebx : 53
>  00000eb1: pushl %edx : 52
> 00000eb2: movl %ds:0x20000=stackLimit, %eax : A1 00 00 02 00
>  00000eb7: cmpl %eax, %esp : 39 C4
> 00000eb9: jb .+0xffffffc5 (0x00000e80=setX:setY:@18) : 72 C5
>  HasBytecodePC:
> 00000ebb: movl 12(%ebp), %eax : 8B 45 0C
> 00000ebe: pushl %eax : 50
>  00000ebf: movl -12(%ebp), %edx : 8B 55 F4
> 00000ec2: popl %ecx : 59
> 00000ec3: movl %ecx, %ds:0x4(%edx) : 89 4A 04
>  00000ec6: movl %ecx, %eax : 89 C8
> 00000ec8: andl $0x00000001, %eax : 83 E0 01
>  00000ecb: jnz .+0x0000001a (0x00000ee7=setX:setY:@7F) : 75 1A
> 00000ecd: movl %ds:0x4e5e400, %eax : A1 00 E4 E5 04
>  00000ed2: cmpl %eax, %edx : 39 C2
> 00000ed4: jnb .+0x00000011 (0x00000ee7=setX:setY:@7F) : 73 11
>  00000ed6: cmpl %eax, %ecx : 39 C1
> 00000ed8: jb .+0x0000000d (0x00000ee7=setX:setY:@7F) : 72 0D
>  00000eda: movb %ds:0x3(%edx), %al : 8A 42 03
> 00000edd: andl $0x00000040, %eax : 83 E0 40
>  00000ee0: jnz .+0x00000005 (0x00000ee7=setX:setY:@7F) : 75 05
> 00000ee2: call .+0xfffffda1 (0x00000c88=ceStoreCheckTrampoline) : E8 A1 FD
> FF FF
>  IsRelativeCall:
> 00000ee7: movl 8(%ebp), %eax : 8B 45 08
> 00000eea: pushl %eax : 50
>  00000eeb: movl -12(%ebp), %edx : 8B 55 F4
> 00000eee: popl %ecx : 59
> 00000eef: movl %ecx, %ds:0x8(%edx) : 89 4A 08
>  00000ef2: movl %ecx, %eax : 89 C8
> 00000ef4: andl $0x00000001, %eax : 83 E0 01
>  00000ef7: jnz .+0x0000001a (0x00000f13=setX:setY:@AB) : 75 1A
> 00000ef9: movl %ds:0x4e5e400, %eax : A1 00 E4 E5 04
>  00000efe: cmpl %eax, %edx : 39 C2
> 00000f00: jnb .+0x00000011 (0x00000f13=setX:setY:@AB) : 73 11
>  00000f02: cmpl %eax, %ecx : 39 C1
> 00000f04: jb .+0x0000000d (0x00000f13=setX:setY:@AB) : 72 0D
>  00000f06: movb %ds:0x3(%edx), %al : 8A 42 03
> 00000f09: andl $0x00000040, %eax : 83 E0 40
>  00000f0c: jnz .+0x00000005 (0x00000f13=setX:setY:@AB) : 75 05
> 00000f0e: call .+0xfffffd75 (0x00000c88=ceStoreCheckTrampoline) : E8 75 FD
> FF FF
>  IsRelativeCall:
> 00000f13: movl -12(%ebp), %edx : 8B 55 F4
> 00000f16: movl %ebp, %esp : 89 EC
>  00000f18: popl %ebp : 5D
> 00000f19: ret $0x000c : C2 0C 00
> 00000f1c: nop  : 90
>  00000f1d: nop  : 90
> 00000f1e: nop  : 90
> 00000f1f: nop  : 90
>  00000f20: nop  : 90
> startpc: 12
>   16rEAB IsAbsPCReference    (16rF27)
>   16rEBB HasBytecodePC       (16rF26, bc: 12)
>   16rEE7 IsRelativeCall      (16rF24)
>   16rF13 IsRelativeCall      (16rF22)
>
> and the following if you choose StackToRegisterMappingCogit:
>
>
> 1128
> objhdr: 1003
> nArgs: 2 type: 2
>  blksiz: B8
> method: 100040
> mthhdr: 4100801
>  selctr: 100048=setX:setY:
> blkentry: 0
> stackCheckOffset: 53/117B
>  00001140: xorl %edx, %edx : 31 D2
> 00001142: call .+0xfffff9b1 (0x00000af8=ceMethodAbortNArgs) : E8 B1 F9 FF
> FF
>  00001147: nop  : 90
> entry:
> 00001148: movl %edx, %eax : 89 D0
>  0000114a: andl $0x00000001, %eax : 83 E0 01
> 0000114d: jnz .+0x00000010 (0x0000115f=setX:setY:@37) : 75 10
>  0000114f: movl %ds:(%edx), %eax : 8B 02
> 00001151: shrl $0x0a, %eax : C1 E8 0A
>  00001154: andl $0x0000007c, %eax : 83 E0 7C
> 00001157: jnz .+0x00000006 (0x0000115f=setX:setY:@37) : 75 06
>  00001159: movl %ds:0xfffffffc(%edx), %eax : 8B 42 FC
> 0000115c: andl $0xfffffffc, %eax : 83 E0 FC
>  0000115f: cmpl %ecx, %eax : 39 C8
> 00001161: jnz .+0xffffffdf (0x00001142=setX:setY:@1A) : 75 DF
>  noCheckEntry:
> 00001163: pushl %ebp : 55
> 00001164: movl %esp, %ebp : 89 E5
>  00001166: pushl $0x00001128=setX:setY:@0 : 68 28 11 00 00
> IsAbsPCReference:
>  0000116b: movl $0x00100000=nil, %ebx : BB 00 00 10 00
> 00001170: pushl %ebx : 53
>  00001171: pushl %edx : 52
> 00001172: movl %ds:0x20000=stackLimit, %eax : A1 00 00 02 00
>  00001177: cmpl %eax, %esp : 39 C4
> 00001179: jb .+0xffffffc5 (0x00001140=setX:setY:@18) : 72 C5
>  HasBytecodePC:
> 0000117b: movl 12(%ebp), %ecx : 8B 4D 0C
> 0000117e: movl -12(%ebp), %edx : 8B 55 F4
>  00001181: movl %ecx, %ds:0x4(%edx) : 89 4A 04
> 00001184: movl %ecx, %eax : 89 C8
>  00001186: andl $0x00000001, %eax : 83 E0 01
> 00001189: jnz .+0x0000001a (0x000011a5=setX:setY:@7D) : 75 1A
>  0000118b: movl %ds:0x4e5e400, %eax : A1 00 E4 E5 04
> 00001190: cmpl %eax, %edx : 39 C2
>  00001192: jnb .+0x00000011 (0x000011a5=setX:setY:@7D) : 73 11
> 00001194: cmpl %eax, %ecx : 39 C1
>  00001196: jb .+0x0000000d (0x000011a5=setX:setY:@7D) : 72 0D
> 00001198: movb %ds:0x3(%edx), %al : 8A 42 03
>  0000119b: andl $0x00000040, %eax : 83 E0 40
> 0000119e: jnz .+0x00000005 (0x000011a5=setX:setY:@7D) : 75 05
>  000011a0: call .+0xfffffd53 (0x00000ef8=ceStoreCheckTrampoline) : E8 53
> FD FF FF
> IsRelativeCall:
>  000011a5: movl 8(%ebp), %ecx : 8B 4D 08
> 000011a8: movl %ecx, %ds:0x8(%edx) : 89 4A 08
>  000011ab: movl %ecx, %eax : 89 C8
> 000011ad: andl $0x00000001, %eax : 83 E0 01
>  000011b0: jnz .+0x0000001a (0x000011cc=setX:setY:@A4) : 75 1A
> 000011b2: movl %ds:0x4e5e400, %eax : A1 00 E4 E5 04
>  000011b7: cmpl %eax, %edx : 39 C2
> 000011b9: jnb .+0x00000011 (0x000011cc=setX:setY:@A4) : 73 11
>  000011bb: cmpl %eax, %ecx : 39 C1
> 000011bd: jb .+0x0000000d (0x000011cc=setX:setY:@A4) : 72 0D
>  000011bf: movb %ds:0x3(%edx), %al : 8A 42 03
> 000011c2: andl $0x00000040, %eax : 83 E0 40
>  000011c5: jnz .+0x00000005 (0x000011cc=setX:setY:@A4) : 75 05
> 000011c7: call .+0xfffffd2c (0x00000ef8=ceStoreCheckTrampoline) : E8 2C FD
> FF FF
>  IsRelativeCall:
> 000011cc: movl -12(%ebp), %edx : 8B 55 F4
> 000011cf: movl %ebp, %esp : 89 EC
>  000011d1: popl %ebp : 5D
> 000011d2: ret $0x000c : C2 0C 00
> 000011d5: nop  : 90
>  000011d6: nop  : 90
> 000011d7: nop  : 90
> 000011d8: nop  : 90
>  startpc: 12
>   16r116B IsAbsPCReference    (16r11DF)
>   16r117B HasBytecodePC       (16r11DE, bc: 12)
>   16r11A5 IsRelativeCall      (16r11DC)
>   16r11CC IsRelativeCall      (16r11DA)
>
> (spot the difference?)
>
>
>> and that answers a possible machine code for that compiled method ? is
>> that possible ? Sorry for my ignorance if this is absurd.
>>
>
> Far from it.
>
>
>>
>> if you provide me such method I plan to build a little browser on top of
>> that.
>>
>
> Go for it.
>
>
>>
>> Thanks
>>
>> --
>> Mariano
>> http://marianopeck.wordpress.com
>>
>>
>>
>
>


-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20110418/a7a1db2b/attachment-0001.htm


More information about the Vm-dev mailing list