[graalvm-dev] Question regarding "target class must inherit directly from Object"

Christian Wimmer christian.wimmer at oracle.com
Fri Feb 19 19:27:41 PST 2021


Hi,

First my usual disclaimer: You should not use substitutions at all. They are a maintenance nightmare.

Nothing has changed in the substitution system for a long time, so the comment is still accurate.
The problem are virtual method calls in target classes. The image generator delegates all virtual method resolution to the HotSpot VM via JVMCI. But the HotSpot VM does not know anything about the substitutions and target classes. So if you have a virtual dispatch in a target class, very strange things could happen. Forcing target classes to be final and inheriting directly from Object means that there are only invokespecial and no dynamic dispatch.

Virtual method calls would also be the only reason for inheriting from target classes. All other use cases can be handled by having separate target classes, e.g. when you have classes A extends B, you can have separate Target_A and Target_B. And you can cast freely between A, B, Target_A, and Target_B - at run time only classes A and B exist.

-Christian
________________________________
From: graalvm-dev-bounces at oss.oracle.com <graalvm-dev-bounces at oss.oracle.com> on behalf of Foivos Zakkak <fzakkak at redhat.com>
Sent: Thursday, February 18, 2021 2:26 PM
To: graalvm-dev at oss.oracle.com <graalvm-dev at oss.oracle.com>
Subject: [graalvm-dev] Question regarding "target class must inherit directly from Object"


Hello all,

In [1] I see:

// Not sure what happens if the target class is in a hierarchy - so prohibit that for now.
guarantee(annotatedClass.isInterface() == originalClass.isInterface(), "if original is interface, target must also be interface: %s", annotatedClass);
guarantee(originalClass.getSuperclass() == Object.class || originalClass.isInterface(), "target class must inherit directly from Object: %s", originalClass);

I was wondering if anything changed since that comment and the corresponding guarantees were added?
Does anyone know it's now safe to remove those guarantees?

Thanks in advance!

[1] https://github.com/oracle/graal/blob/51fe078b16e61bc50d95bdbbee9b0b0886b4c98d/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java#L573-L575

--
Foivos Zakkak
Senior Software Engineer, R&D Middleware
Red Hat
7B40 69D9 29BA AE91 C0B3 220A 0846 BFD1 03F0 4EA1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-dev/attachments/20210220/4f45fbe4/attachment.html 


More information about the GraalVM-Dev mailing list