Skip to content

RuntimeHintsAgent should not require full reflection on types #29091

Closed
@bclozel

Description

@bclozel

Currently, the RuntimeHintsAgent is too strict and does not fully replicate the behavior of a GraalVM native application when it comes to reflection.

Assuming the following registered reflection hint:

{
  "name" : "scratch.QueriedClass",
  "methods" : [
    { "name" : "firstMethod" },
  ]
}

for the following class

package scratch:

class QueriedClass {

  void firstMethod() { }

  void secondMethod() { }
}

A GraalVM native application will behave like this:

Method firstMethod = QueriedClass.class.getMethod("firstMethod");

// this will throw a NoSuchMethodException since no metadata was registered
Method secondMethod = QueriedClass.class.getMethod("secondMethod");

// this will return an array with a single method, "firstMethod"
Method[] methods = QueriedClass.class.getMethods();

Currently the Java agent and its testing infrastructure will require full method introspection on the type when Class.getMethods() is called. We should instead do the following:

  • do not require full method reflection on the type when this is called
  • align other parts of the instrumentation with this principle (fields...)
  • ensure that key methods on those elements acquired through reflection are instrumented to ensure that they're not used without reflection later in the process. This means that Method.invoke() and other key methods should be instrumented.

Metadata

Metadata

Assignees

Labels

theme: aotAn issue related to Ahead-of-time processingtype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions