JIT and ContextPart/Exception issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JIT and ContextPart/Exception issue

Holger Freyther
Hi,

I am currently toying with Phexample (an extension of SUnit) and implement
the "visitor" for the CompiledCode and wanted to use the JIT for that.

Object subclass: PhexampleInstructionMatcher [
    bytecodeIndex: anIndex with: aParam [
        Transcript nextPutAll: 'BC '; nextPutAll: anIndex printString; nl.
        anIndex printNl.
    ]

    lineNo: aLine with: aParam [
        Transcript nextPutAll: 'Line '; nextPutAll: aLine printString; nl.
    ]
]

st> (CompiledCode >> #examineOn:) dispatchTo: PhexampleInstructionMatcher new with: nil

Result on JIT:
Object: PhexampleInstructionMatcher new "<0x40445ec0>" error: did not understand #pushSelf:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
PhexampleInstructionMatcher(Object)>>doesNotUnderstand: #pushSelf: (SysExcept.st:1408)
CompiledMethod(CompiledCode)>>dispatchByte:with:at:to:with: (CompildCode.st:618)
[] in Object: BlockContext new: 16 "<0x4044ab40>" error: IP(35) is not correct
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
PhexampleInstructionMatcher(Object)>>doesNotUnderstand: #pushSelf: (SysExcept.st:1408)
CompiledMethod(CompiledCode)>>dispatchByte:with:at:to:with: (CompildCode.st:618)
[] in Object: BlockContext new: 16 "<0x4044ab40>" error: IP(35) is not correct
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
...
infinite loop


Result on Interpreter:
Object: PhexampleInstructionMatcher new "<0x40437ec0>" error: did not understand #pushSelf:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
PhexampleInstructionMatcher(Object)>>doesNotUnderstand: #pushSelf: (SysExcept.st:1408)
CompiledMethod(CompiledCode)>>dispatchByte:with:at:to:with: (CompildCode.st:618)
[] in CompiledMethod(CompiledCode)>>dispatchTo:with: (CompildCode.st:569)
CompiledMethod(CompiledCode)>>dispatchSuperoperator:with:at:to: (CompildCode.st:661)
CompiledMethod(CompiledCode)>>dispatchSuperoperator:with:at:to: (CompildCode.st:656)
CompiledMethod(CompiledCode)>>allByteCodeIndicesDo: (CompildCode.st:1032)
CompiledMethod(CompiledCode)>>dispatchTo:with: (CompildCode.st:558)
UndefinedObject>>executeStatements (a String:1)


Info:
(CompiledCode >> #dispatchByte:with:at:to:with:) sourceCodeMap
(1 0 0 0 5 0 5 0 5 0 5 0 7 0 7 0 8 0 9 0 10 0 11 0 11 0 11 0 12 0 12 0 12 0 14 0 15 0 16 0 17 0 18 0 18 0 18 0 19 0 19 0 19 0 21 0 22 0 23 0 24 0 25 0 25 0 25 0 26 0 26 0 26 0 28 0 29 0 30 0 31 0 32 0 32 0 32 0 33 0 33 0 33 0 35 0 36 0 37 0 38 0 39 0 39 0 39 0 40 0 40 0 40 0 42 0 43 0 44 0 45 0 45 0 45 0 46 0 46 0 46 0 46 0 46 0 46 0 46 0 46 0 47 0 47 0 47 0 47 0 47 0 47 0 47 0 48 0 48 0 48 0 48 0 )


Paolo any idea where we can start to look for the issue?

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: JIT and ContextPart/Exception issue

Holger Freyther
On Mon, Jan 20, 2014 at 02:44:38PM +0100, Holger Hans Peter Freyther wrote:

Hi Paolo,

I now understand the issue but I don't have a re-producer or a fix.

> [] in Object: BlockContext new: 16 "<0x4044ab40>" error: IP(35) is not correct

[] in An instance of BlockContext
  parent: CompiledMethod(CompiledCode)>>dispatchSuperoperator:with:at:to: (CompildCode.st:661)
  nativeIP: 79831804
  ip: 34
  sp: 3

...
   [33] send 5 args message #dispatchByte:with:at:to:with:
   [37] return stack top

dispatchTo: anObject with: param [
        "Disassemble the bytecodes and tell anObject about them in the form
         of message sends.  param is given as an argument to every message
         send."

        <category: ''decoding bytecodes''>
        | lastOfs |
        self allByteCodeIndicesDo:
                [:i :byte :arg |
                lastOfs = i
                    ifFalse:
                        [anObject bytecodeIndex: i with: param.
                        lastOfs := i].
                self
                    dispatchByte: byte
                    with: arg
                    at: i
                    to: anObject
                    with: param]
    ]


So 34 + 1 would point to "35" but there is no bytecode at this offset. The
next one is at "37". As a hack I found the below to work. So the usage of
BYTECODE_SIZE is wrong in this case. The code_tree should know the number
of bytecodes used for the send. Is this somehow possible?

@@ -1411,6 +1413,7 @@ void
 gen_send (code_tree *tree)
 {
   inline_cache *ic = (inline_cache *) tree->data;
+  int offset = BYTECODE_SIZE;
 
   PUSH_CHILDREN;
   jit_movi_p (JIT_V1, ic);
@@ -1419,7 +1422,12 @@ gen_send (code_tree *tree)
   else
     EXPORT_SP (JIT_V0);
 
-  jit_movi_ul (JIT_R0, tree->bp - bc + BYTECODE_SIZE);
+  if (tree->bp - bc + BYTECODE_SIZE == 34 && in_block) {
+   printf("Code...?\n");
+   offset += BYTECODE_SIZE;
+  }
+
+  jit_movi_ul (JIT_R0, tree->bp - bc + offset);
   jit_ldxi_p (JIT_R1, JIT_V1, jit_field (inline_cache, cachedIP));
   jit_sti_ul (&ip, JIT_R0);
 
@@ -1427,7 +1435,7 @@ gen_send (code_tree *tree)
   jit_align (2);
 
   ic->native_ip = jit_get_label ();
-  define_ip_map_entry (tree->bp - bc + BYTECODE_SIZE);
+  define_ip_map_entry (tree->bp - bc + offset);


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: JIT and ContextPart/Exception issue

Holger Freyther
On Sat, Feb 01, 2014 at 06:28:07PM +0100, Holger Hans Peter Freyther wrote:
> On Mon, Jan 20, 2014 at 02:44:38PM +0100, Holger Hans Peter Freyther wrote:
>
> Hi Paolo,

Hi again,

so maybe there are two bugs. The JIT should not assume a "dense" bytecode
and actually know where/if there is a next bytecode and somehow I think
there should not be a gap? The below is the easiest re-producer of the
issue.


Object subclass: Foo [
        bytecodeIndex [
        ]

        dispatchTo [
        "Disassemble the bytecodes and tell anObject about them in the form
         of message sends.  param is given as an argument to every message
         send."

        <category: 'decoding bytecodes'>
        | lastOfs anObject param i byte arg |
                anObject := self.
                "Remove the send to have the issue go away"
                anObject bytecodeIndex.
                self
                    dispatchByte: byte
                    with: arg
                    at: i
                    to: anObject
                    with: param
    ]
]

Eval [
"        ((CompiledMethod lookupSelector: #dispatchTo:with:) literalAt: 3) inspect.
        (CompiledMethod lookupSelector: #dispatchTo:with:) methodSourceString printNl.
        (Foo >> #dispatchTo) inspect."

        Foo new dispatchTo
]


An instance of CompiledMethod
  header: 12416
  Header Flags:
    flags: 0
    primitive index: 0
    number of arguments: 0
    number of temporaries: 6
    number of literals: 2
    needed stack slots: 16
  descriptor: a MethodInfo
  literals: [
    [1] #bytecodeIndex
    [2] #dispatchByte:with:at:to:with:
  ]
  byte codes: [
Code...?
    [1] source code line number 5
    [3] source code line number 8
        push self
    [5] store into Temporary[1]
        source code line number 9
    [7] send 0 args message #bytecodeIndex
    [9] source code line number 10
        pop stack top
        push self
   [11] source code line number 11
        push Temporary[4]
   [13] source code line number 12
   [15] push Temporary[5]
   [17] source code line number 13
        push Temporary[3]
   [19] source code line number 14
        push Temporary[1]
   [21] source code line number 15
        push Temporary[2]
   [23] send 5 args message #dispatchByte:with:at:to:with:
   [27] push self
        return stack top
  ]


note [23] and [27]. I am not sure if there is actually anything
between these two?

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk