CodeLocalsShifter

Adam Sotona adam.sotona at oracle.com
Tue Dec 3 07:08:30 UTC 2024


Hi Mark,
CodeLocalsShifter shifts all locals passing through it to a newly allocated slots, except for the receiver and method parameters slots (which are protected).

Its purpose is to allow more complex (multi-source) transformation, as shown for example here:
https://download.java.net/java/early_access/jdk24/docs/api/java.base/java/lang/classfile/components/package-summary.html#class-instrumentation-sample-heading
When you have two sources of code (`instrumentor` and `target` in the example), you have to avoid collisions of the locals slots. In the example the instrumentor code precedes the injected target code, so the target code must be re-allocated  to the new locals slots beyond the instrumentor code (however method parameter slots must stay unchanged).

It should be no problem to add a new CodeLocalsShifter  factory method, where you can specify the number of protected slots. Current factory calculates the protected slots from the method parameters, so it is more convenient for the intended use.

Feel free to ask if you have any further questions.

Thank you,
Adam

From: classfile-api-dev <classfile-api-dev-retn at openjdk.org> on behalf of Mark Roberts <markro at cs.washington.edu>
Date: Saturday, 30 November 2024 at 0:54
To: Chen Liang <chen.l.liang at oracle.com>, classfile-api-dev at openjdk.org <classfile-api-dev at openjdk.org>
Subject: CodeLocalsShifter
CodeLocalsShifter seems to shift the locals down a variable number based on the number of current locals.  How do I shift the locals down a fixed number that I designate?

Thanks,
Mark

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20241203/b0d064d3/attachment-0001.htm>


More information about the classfile-api-dev mailing list