Hi thierry

f this implementation follows persephone
the bytecode is the result of the first execution of the AST. So a kind of JIT inside the system. The AST is annotated with properties (link to meta objects that can define the semantics of the annotation).

Stef

Le 27/2/15 19:48, Thierry Goubier a écrit :
Hi Markus,

if I understand correctly some of the possibilities:

- I can use RBParseTreeSearcher / RBParseTreeRewriter on the twin AST.

(any example how to install / invalidate the twin AST after an effective RBParseTreeRewriter operation?)

- Any change to the Twin AST is reflected in the method bytecode (as long as one does invalidate).

This would mean being able to put tracing code with RB patterns, no? And without having to do a recompilation of the traced method?

Thierry

Le 27/02/2015 00:07, Marcus Denker a écrit :
Hi,

In 40516 there is now a strange, but rather powerful mechanism for CompiledMethod: the Twin.

What does that do?

you can call on a method #createTwin

    (ReflectivityExamples>>#exampleMethod) createTwin.

after this, the CompiledMethod has a high-level representation (the AST) attached that itself references the CompiledMethod
(they form a twin).

    (ReflectivityExamples>>#exampleMethod) reflectiveMethod

The fun thing is now that one can install either in the class. Call #invalidate to make sure the reflective method is installed.

ReflectiveMethod implements #run:with:in: which calls a compilation hook (too re-create from the AST) and then installs that in the
method dict and then executes the method:

    (ReflectivityExamples>>#exampleMethod) createTwin.
    (ReflectivityExamples>>#exampleMethod) invalidate.
self assert: (ReflectivityExamples>>#exampleMethod) class = ReflectiveMethod.
    self assert: ReflectivityExamples new exampleMethod = 5.
self assert: (ReflectivityExamples>>#exampleMethod) class = CompiledMethod.

Which means that this gives us an in-image, on-demand JIT compiler AST->Bytecode. In 50 lines of code.

e.g. try on Morph:

Morph methods do: #createTwin.
Morph methods do: #invalidate.

Counting which twin is installed shows us the working set of Morph:

(Morph methods select: [ :each | each class = CompiledMethod ]) size

some 330 method out of nearly 900….

So what can one do with this? In essence this turns the AST into a reflective representation for Methods
(if you care to set up twin creation + invalidation correctly).

What will this allow us to do? stay tuned...

    Marcus









Reply via email to