![]() Syntax: public String replace(char oldcharacter, char newcharacter) When used with assisted configuration, conditional entries of existing configuration will not be fused with agent-collected entries.Īlternatively, a custom Feature implementation can register program elements before and during the analysis phase of the native image build using the RuntimeReflection class.Web development, programming languages, Software testing & others When a configuration entry should be enabled if one of several types are reachable, it is necessary to add two configuration entries: one entry for each condition. When the same condition is used for two distinct elements in two configuration entries, both elements will be included when the condition is satisfied. If a condition is omitted, the element is always included. The consistent usage of condition results in smaller binaries and better build times as the image builder can selectively include reflectively accessed code. The following ways to declare and populate an array are equivalent from the point of view of the analysis: Class params0 = new Class,Ĭonditional configuration is the preferred way to specify reflection configuration: if code doing a reflective access is not reachable, it is unnecessary to include its corresponding reflection entry. The analysis runs to a fix point which means that a chain of calls like Class.forName(String).getMethod(String, Class) will first replace the class constant and then the method will effectively reduce this to .įollowing are examples of calls that can be intercepted and replaced with the corresponding element: Class.forName("")Ĭlass.forName("", true, ClassLoader.getSystemClassLoader())Ĭlass.forName("").getMethod("equals", Object.class) The only exception to the constant arguments rule is that the ClassLoader argument of Class.forName(String, ClassLoader) does not need to be a constant it is ignored and instead a class loader that can load all the classes on the class path is used. That is why the analysis does not accept Class arguments coming from static fields, since the contents of those can change at any time, even if the fields are final.Īlthough this may seem too restrictive, it covers the most commonly used patterns of the Reflection API calls. The analysis follows a simple rule: if all the writes to the array happen in linear sections of code, i.e., no control flow splits, then the array is effectively constant for the purpose of analyzing the call. Therefore, all the changes to the array between the time it is allocated and the time it is passed as an argument need to be tracked. This last restriction is due to the fact that Java does not have immutable arrays. The calls are intercepted and processed only when it can be unequivocally determined that the parameters can be reduced to a constant.įor example, the call Class.forName(String) will be replaced with a Class literal only if the String argument can be constant folded, assuming that the class is actually on the classpath.Īdditionally, a call to Class.getMethod(String, Class) will be processed only if the contents of the Class argument can be determined with certainty. Second, GraalVM can employ constant folding and optimize the code further. If the target elements cannot be resolved, e.g., a class is not on the classpath or it does not declare a field/method/constructor, then the calls are replaced with a snippet that throws the appropriate exception at run time.įirst, at run time there are no calls to the Reflection API. If the target elements can be resolved, the calls are removed and instead the target elements are embedded in the code. ![]() ![]() If the arguments to these calls can be reduced to a constant, Native Image tries to resolve the target elements. The analysis intercepts calls to Class.forName(String), Class.forName(String, ClassLoader), Class.getDeclaredField(String), Class.getField(String), Class.getDeclaredMethod(String, Class), Class.getMethod(String, Class), Class.getDeclaredConstructor(Class), and Class.getConstructor(Class). See also the guide on assisted configuration of Java resources and other dynamic features. ![]() Where the analysis fails, the program elements reflectively accessed at run time must be specified using a manual configuration. Native Image tries to resolve the target elements through a static analysis that detects calls to the Reflection API. (Note: loading classes with Class.forName(String) are included here since it is closely related to reflection.) Native Image has partial support for reflection and needs to know ahead-of-time the reflectively accessed program elements.Įxamining and accessing program elements through .* or loading classes with Class.forName(String) at run time requires preparing additional metadata for those program elements. ![]() Java reflection support (the .* API) enables Java code to examine its own classes, methods, fields and their properties at run time. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |