Determine if a method is Jitted or not
Hi All, anybody knows how to check if a method is jitted or not? I remember (maybe wrongly) that the Jit in Cog has a configurable limit on the number of bytecodes for a method to be jitted or not; I'm looking into the performance of generated code where I can, more or less, control the length of methods (SmaCC) and I'd like to find the optimum point. Thanks, Thierry
2015-02-23 14:05 GMT+01:00 Thierry Goubier <thierry.goubier@gmail.com>:
Hi All,
Hello,
anybody knows how to check if a method is jitted or not?
I don't think there's a way to do that.
I remember (maybe wrongly) that the Jit in Cog has a configurable limit on the number of bytecodes for a method to be jitted or not; I'm looking into the performance of generated code where I can, more or less, control the length of methods (SmaCC) and I'd like to find the optimum point.
Any method is jitted if when activated it's already in the global lookup
cache and it's not already jitted (so mostly on second calls). The only limit is on the number of literals. A method with more than a certain number of literals (by default, 64) is not jitted. You can change this limit by starting the VM with a specific command line argument (I don't remember, something like --maxNumLiterals, you will find it when pressing --help I don't have access to a VM right now). Basically the limit is to 64 because the GC consume a lot of time in the machine code zone. Each literals require specific care because their addresses are directly in the generated code (Has the literal moved in memory, ...). There's a few other things, such as a method with unknown bytecodes will not be jitted (so you can rely for example on the respondsToUnknownBytecode hook with interpreted methods), but I don't think it matters for you.
Thanks,
Thierry
Hi Clement, 2015-02-23 14:46 GMT+01:00 Clément Bera <bera.clement@gmail.com>:
Any method is jitted if when activated it's already in the global lookup cache and it's not already jitted (so mostly on second calls).
Ok.
The only limit is on the number of literals. A method with more than a certain number of literals (by default, 64) is not jitted. You can change this limit by starting the VM with a specific command line argument (I don't remember, something like --maxNumLiterals, you will find it when pressing --help I don't have access to a VM right now). Basically the limit is to 64 because the GC consume a lot of time in the machine code zone. Each literals require specific care because their addresses are directly in the generated code (Has the literal moved in memory, ...).
64 literals in a method... This means something like : aCompiledMethod numLiterals <= 64 Would reasonably tells me which methods will be jitted.
There's a few other things, such as a method with unknown bytecodes will not be jitted (so you can rely for example on the respondsToUnknownBytecode hook with interpreted methods), but I don't think it matters for you.
And unknown bytecodes won't be generated by standard smalltalk code, right? So it shouldn't matter to me. This is very helpful, thanks. Thierry
2015-02-23 15:08 GMT+01:00 Thierry Goubier <thierry.goubier@gmail.com>:
Hi Clement,
2015-02-23 14:46 GMT+01:00 Clément Bera <bera.clement@gmail.com>:
Any method is jitted if when activated it's already in the global lookup cache and it's not already jitted (so mostly on second calls).
Ok.
The only limit is on the number of literals. A method with more than a certain number of literals (by default, 64) is not jitted. You can change this limit by starting the VM with a specific command line argument (I don't remember, something like --maxNumLiterals, you will find it when pressing --help I don't have access to a VM right now). Basically the limit is to 64 because the GC consume a lot of time in the machine code zone. Each literals require specific care because their addresses are directly in the generated code (Has the literal moved in memory, ...).
64 literals in a method... This means something like :
aCompiledMethod numLiterals <= 64
Would reasonably tells me which methods will be jitted.
Yes. This is the code in VMMAker: ^(objectMemory literalCountOfMethodHeader: methodHeader) <= maxLiteralCountForCompile
There's a few other things, such as a method with unknown bytecodes will not be jitted (so you can rely for example on the respondsToUnknownBytecode hook with interpreted methods), but I don't think it matters for you.
And unknown bytecodes won't be generated by standard smalltalk code, right? So it shouldn't matter to me.
No. But I wrote that just so you know if you start doing exotic things there are other constraints than just the number of literals.
This is very helpful, thanks.
Thierry
Hi Thierry, there's an unadvertised primitive called Context>>#xRay (or ContextPart>>#xRay) that answers these questions for tests. I'm away from the system right now but I'll get you the source soon. Also, the limit on jutting methods, 60 literals, is a default. There's a command line option -maxcoglits (IIRC) that you can change. Eliot (phone) On Feb 23, 2015, at 5:05 AM, Thierry Goubier <thierry.goubier@gmail.com> wrote:
Hi All,
anybody knows how to check if a method is jitted or not?
I remember (maybe wrongly) that the Jit in Cog has a configurable limit on the number of bytecodes for a method to be jitted or not; I'm looking into the performance of generated code where I can, more or less, control the length of methods (SmaCC) and I'd like to find the optimum point.
Thanks,
Thierry
2015-02-23 16:36 GMT+01:00 Eliot Miranda <eliot.miranda@gmail.com>:
Hi Thierry,
there's an unadvertised primitive called Context>>#xRay (or ContextPart>>#xRay) that answers these questions for tests. I'm away from the system right now but I'll get you the source soon. Also, the limit on jutting methods, 60 literals, is a default. There's a command line option -maxcoglits (IIRC) that you can change.
Thanks Eliot! It's helping a lot to guide me, even if I have to work at the ast level and, as a result, I estimate the number of literals in the bytecode by counting the number of literal nodes in the AST, with the approximation that ~100 literal nodes will make it under the limit. Making it under the limit shaves 30% of the execution time of a parse with SmaCC. And it avoids the too long methods as a side benefit. I would dream of having precise ways of estimating things like that on the AST. It's interesting to hit those "I'd like to be able to predict the performance of that piece of code" issues. Thierry
Eliot (phone)
On Feb 23, 2015, at 5:05 AM, Thierry Goubier <thierry.goubier@gmail.com> wrote:
Hi All,
anybody knows how to check if a method is jitted or not?
I remember (maybe wrongly) that the Jit in Cog has a configurable limit on the number of bytecodes for a method to be jitted or not; I'm looking into the performance of generated code where I can, more or less, control the length of methods (SmaCC) and I'd like to find the optimum point.
Thanks,
Thierry
On Feb 23, 2015, at 7:50 AM, Thierry Goubier <thierry.goubier@gmail.com> wrote:
2015-02-23 16:36 GMT+01:00 Eliot Miranda <eliot.miranda@gmail.com>:
Hi Thierry,
there's an unadvertised primitive called Context>>#xRay (or ContextPart>>#xRay) that answers these questions for tests. I'm away from the system right now but I'll get you the source soon. Also, the limit on jutting methods, 60 literals, is a default. There's a command line option -maxcoglits (IIRC) that you can change.
Thanks Eliot!
It's helping a lot to guide me, even if I have to work at the ast level and, as a result, I estimate the number of literals in the bytecode by counting the number of literal nodes in the AST, with the approximation that ~100 literal nodes will make it under the limit.
Making it under the limit shaves 30% of the execution time of a parse with SmaCC. And it avoids the too long methods as a side benefit.
I would dream of having precise ways of estimating things like that on the AST. It's interesting to hit those "I'd like to be able to predict the performance of that piece of code" issues.
Alas two things other than the AST affect the number of literals. First is the specialSelectors; these are used for sends only. So if a method only sends one of the special selectors the selector will not occur in the method as a literal. Second is the bytecode set. While we only have one set now, Sista is introducing another, and Newspeak has its own. In the current set, -1, 0, 1 & 2 and true and false have bytecodes to push these literals, so they don't occur as literals in methods. In both the Sista and the Newspeak sets there are bytecodes that encode a much wider range of integers and characters as bytecodes (a push literal bytecode takes 1 byte for the bytecode and 4 or 8 bytes for the literal; a bytecode for the 16-bit integer range takes 3 bytes). Another thing that affects the number of literals is the compiler's decision to include selectors for optimized methods such as ifTrue: et al (which I think is a very good thing). If you could ask the back end which literal would be encoded as a literal (and if course the question is asked when bytecode is generated) you could get a more accurate count. HTH
Thierry
Eliot (phone)
On Feb 23, 2015, at 5:05 AM, Thierry Goubier <thierry.goubier@gmail.com> wrote:
Hi All,
anybody knows how to check if a method is jitted or not?
I remember (maybe wrongly) that the Jit in Cog has a configurable limit on the number of bytecodes for a method to be jitted or not; I'm looking into the performance of generated code where I can, more or less, control the length of methods (SmaCC) and I'd like to find the optimum point.
Thanks,
Thierry
On 23 Feb 2015, at 18:07, Eliot Miranda <eliot.miranda@gmail.com> wrote:
On Feb 23, 2015, at 7:50 AM, Thierry Goubier <thierry.goubier@gmail.com <mailto:thierry.goubier@gmail.com>> wrote:
2015-02-23 16:36 GMT+01:00 Eliot Miranda <eliot.miranda@gmail.com <mailto:eliot.miranda@gmail.com>>: Hi Thierry,
there's an unadvertised primitive called Context>>#xRay (or ContextPart>>#xRay) that answers these questions for tests. I'm away from the system right now but I'll get you the source soon. Also, the limit on jutting methods, 60 literals, is a default. There's a command line option -maxcoglits (IIRC) that you can change.
Thanks Eliot!
It's helping a lot to guide me, even if I have to work at the ast level and, as a result, I estimate the number of literals in the bytecode by counting the number of literal nodes in the AST, with the approximation that ~100 literal nodes will make it under the limit.
Making it under the limit shaves 30% of the execution time of a parse with SmaCC. And it avoids the too long methods as a side benefit.
I would dream of having precise ways of estimating things like that on the AST. It's interesting to hit those "I'd like to be able to predict the performance of that piece of code" issues.
Alas two things other than the AST affect the number of literals. First is the specialSelectors; these are used for sends only. So if a method only sends one of the special selectors the selector will not occur in the method as a literal. Second is the bytecode set. While we only have one set now, Sista is introducing another, and Newspeak has its own. In the current set, -1, 0, 1 & 2 and true and false have bytecodes to push these literals, so they don't occur as literals in methods. In both the Sista and the Newspeak sets there are bytecodes that encode a much wider range of integers and characters as bytecodes (a push literal bytecode takes 1 byte for the bytecode and 4 or 8 bytes for the literal; a bytecode for the 16-bit integer range takes 3 bytes).
Another thing that affects the number of literals is the compiler's decision to include selectors for optimized methods such as ifTrue: et al (which I think is a very good thing).
If you could ask the back end which literal would be encoded as a literal (and if course the question is asked when bytecode is generated) you could get a more accurate count.
Another thing that we use the literal array for is (will be) meta object⦠if you annotate an AST node or variable with a MetaLink, it stores that in the literal array. For example: link := MetaLink new metaObject: Halt; selector: #now. then installing this on some AST node (or Slot) will lead to bytecode like ... pushLiteral: Halt send: #now ... This means that the meta object is stored in the literal frame of the compiledMethod (the Link itself is just an annotation on the structural element). Marcus
participants (4)
-
Clément Bera -
Eliot Miranda -
Marcus Denker -
Thierry Goubier