| ▲ | steve_barham 6 hours ago | |
I did something similar a few years back, with a slightly different approach to declaration, using interfaces to denote the layout of the struct. Mutation was opt-in by exposing setters using the (of the time) standard JavaBeans layout and an annotation processor took care of the codegen of an implementing class, which could be used where you wanted an on-heap box of an off-heap structure. One benefit of this approach was that by using the interface as the type you could fairly easily support a flyweight pattern, reducing GC pressure when working with large off-heap collections. The parallels between stateless interfaces and offheap structs was also quite pleasing. I'd love to see a similar effort using more modern techniques than Unsafe et al. | ||
| ▲ | joe_mwangi 5 hours ago | parent | next [-] | |
Interesting approach. I think Project Babylon did the same thing https://github.com/openjdk/babylon/blob/code-reflection/hat/... I had tested it and it's quite fast. Actually, you don't need to generate any bytecode on the fly. Problem is when you deal with array as fields, implementation becomes difficult. You can revisit if interested to come back to such an implementation one day. | ||
| ▲ | naxios_official 5 hours ago | parent | prev | next [-] | |
[dead] | ||
| ▲ | naxios_official 5 hours ago | parent | prev [-] | |
[flagged] | ||