Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-50962] Add object reachability hooks. #8041

Merged
merged 2 commits into from
Dec 17, 2023

Conversation

graalvmbot
Copy link
Collaborator

No description provided.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Dec 16, 2023
@kkriske
Copy link
Contributor

kkriske commented Jan 29, 2024

registerObjectReachableCallback is currently only available in the DuringSetupAccessImpl class, which is not part of the public API.
Adding it to the DuringSetupAccess interface would allow end users to use this call instead of the object replacer as well.
@olpaw could this be considered ad a candidate to add to the public API? Tagging you because of the work you did on #4783

@christianwimmer
Copy link
Member

@kkriske Do you have a concrete use case where you need this as public API.

For now, we left it internal so that we can evolved and test it. We are also not sure how it will interact with layered images. But if there is a good external use case, we can consider making it supported API.

@kristofdho
Copy link

kristofdho commented Feb 20, 2024

@christianwimmer In general cases where static objects need some additional work to trigger lazy loading of e.g. classes from files.
Something in this form:

class Util {
    public static final ClassHolder EXAMPLE_CLASS = new ClassHolder("org.example.Example");
}

class ClassHolder {
    private final String className;
    private Class<?> classValue;

    public ClassHolder(String className) {
        this.className = className;
    }

    public Class<?> getClassValue() {
        if (classValue == null) {
            try {
                classValue = Class.forName(className);
            } catch (ClassNotFoundException e) {
                classValue = Object.class;
            }
        }
        return classValue;
    }
}

What we currently do, is initialize the Util class at build time, iterate over its fields, capture the ones of type ClassHolder and call getClassValue to trigger class loading and avoid reflection config.

I've now realized it would be easier to use object replacers, but then the registerObjectReachableCallback is intended to replace that specific usecase to avoid abusing the object replacers outside of their intended purpose. Hence the request to expose this to public API.

We have multiple similar, and more complex usecases, mostly aimed at reducing the need of reflection and/or resource config, because manual config, or even automated collection with the agent, is unfeasable.
One of these usecases is situated in Apache POI, which would require us to craft e.g. a test that uses all possible excel features to make sure there are no possible runtime failures due to missing reflection/resource config. We don't know what excel files will be thrown at this at runtime.

PS: same person as @kkriske, but on this account I have access to the relevant resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants