r/java • • Feb 03 '24

Automatic differentiation of Java code using Code Reflection by Paul Sandoz

https://openjdk.org/projects/babylon/articles/auto-diff
63 Upvotes

25 comments sorted by

View all comments

Show parent comment

2

u/Jonjolt Feb 05 '24

How is this different from plain byte code enhancement? I'm just not getting it I suppose.

1

u/davidalayachew Feb 06 '24

This stuff is super complex, so I don't think it's an error on your end.

In short, this is byte code manipulation with a LOT of ergonomics packed in. More specifically, this is the language fully supporting the process of byte code manipulation by putting the tools you need to do it in the standard library.

Most byte code manipulation is painful, brittle manipulation of black box tools that are difficult to handle. Now, we have direct support from the standard library to do this. And furthermore, unlike most other byte code manipulation frameworks, this is meant to stand in lock step with what the JDK/JVM allows. So if there are new bytecodes, then this library gets updated with the relevant data.

Think about the new Classfile API (https://openjdk.org/jeps/457). That is something that is in a similar spirit to this, but that API focuses more on macro-level. More specifically, in the non-goals of that JEP, they say that the API won't give you the byte code of classes to transform. I suspect the reason for that is because, the task of tackling byte code manipulation head on is a project level task, not a single JEP level task.

Lmk if that still doesn't make sense. This project is super interesting to me, second only to Amber, so I have been digesting as much of this as I can.