Does invokevirtual break Scalar Replacement on Java?

208 views Asked by At

I am looking to refactor my application to allow Escape Analysis and Scalar Replacement to kick in for one particular object, that's allocated very often.
I assume I will not hit any inlining limits in JVM because I can just tune in case there is need (full inlining is one of the needs for Scalar Replacement to work)

Assuming a basic code flow like this:

public class DataHandler {
// IHandler is an interface of which there are 4 different implementations at runtime
  private IHandler handler; // child handler - implementation

  public void handleData(SomeData data) {
    HeavyObjectIWantToScalarReplace obj = new HeavyObjectIWantToScalarReplace(data);
    handler.handle(obj)
  }
}

Is invoking a virtual method with object enough to break scalar replacement with latest OpenJDK or OpenJ9? If so, what solution could be used that would be the closest to current OOP approach while avoiding invokevirtual?
Maybe invokevirtual can be optimized out by JIT and it is enough to make sure none of these 4 handler classes are "leaking" reference to HeavyObjectIWantToScalarReplace?

0

There are 0 answers