3

I was reading the following presentation: http://wingolog.org/pub/qc-2012-js-slides.pdf which talks about (4,10,19) inline ASM generation as a technique used in Javascript optimisation.

In the following paper: https://sites.google.com/site/juliangamble/Home/Compilers%20Tutorial%202006-09-16.pdf?attredirects=0&d=1 at page 30 and 31 they talk about using scheme to generate ASM that is subsequently linked and executed in a subsequent OS process.

What about the scenario where you want to generate the ASM and execute it inside your existing process? (ie no subsequent link and execute in separate steps).

I assume this comes down to (in C for example) generating the ASM, writing the bytes to an area of memory (code as data) and adding a function header and return (compatible with a C caller (similar to what we see on page 3 of the Goloum paper above). Then we take that data pointer and convert it to a function pointer and call it (code as code - from code as data).

My questions are:

(a) What is the terminology for this inline code generation and execution?

(b) Is there a simple 'hello world' C example of this available?

hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • I would call it just-in-time (JIT) compilation. A number of Scheme implementations use it, such as Racket and Larceny. – C. K. Young Aug 28 '12 at 23:07
  • This is quite similar to this question http://stackoverflow.com/questions/3073653/can-function-pointers-be-used-to-run-data (but with no example) - they call it self-modifying code - which I'm not sure I agree with the categorisation in my case – hawkeye Aug 30 '12 at 02:22

1 Answers1

1

There is quite a good example here. Again they use the terminology of self-modifying code.

Another one here.

Here they give it four categories (use cases):

  • Metamorphism
  • Trampolining
  • JIT compilation
  • Security implications (insecure coding/malware)

There is a discussion here about whether LISP is truly self-modifying - and they end up concluding that it is not.

Community
  • 1
  • 1
hawkeye
  • 34,745
  • 30
  • 150
  • 304