On Thursday, May 10, 2012 at 6:44 PM, Mike Pall wrote: > Joshua Ballanco wrote: > > [...] but would it be possible (in theory) to combine something > > like the trampolines from imp_implementationWithBlock with > > Return-oriented Programming (possibly with the benefit of a > > pre-built page containing common code sequences) to achieve > > something like a JIT compiler? > > > > > Sure. But that's sort of the opposite of a call-threaded > interpreter (call opcode_a; call opcode_b; ...). So it's really > more like an interpreter, not a JIT compiler. > > And a terribly slow one, too: returns are only branch-predicted > when there was a previous matching call (most CPUs have a small > internal return address prediction stack). Otherwise, the return > is mispredicted, which is very costly: a full pipeline flush costs > about 7-20 cycles, depending on the CPU. You really, really don't > want a full pipeline flush every other instruction. ;-) > > Ah, totally makes sense. I hadn't even considered attempts to predict past returns. Thanks for the information. (I see I still have a lot to learn!)