Skip to content

Commit

Permalink
Consider all types as registered for JNI
Browse files Browse the repository at this point in the history
  • Loading branch information
loicottet committed Oct 10, 2024
1 parent f999f5c commit 1d0c403
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class LegacyReflectionConfigurationParser<C, T> extends ReflectionConfigur

LegacyReflectionConfigurationParser(ConfigurationConditionResolver<C> conditionResolver, ReflectionConfigurationParserDelegate<C, T> delegate, boolean strictConfiguration,
boolean printMissingElements, boolean treatAllNameEntriesAsType) {
super(conditionResolver, delegate, strictConfiguration, printMissingElements);
super(conditionResolver, delegate, strictConfiguration, printMissingElements, "");
this.treatAllNameEntriesAsType = treatAllNameEntriesAsType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ public abstract class ReflectionConfigurationParser<C, T> extends ConfigurationP

protected final ConfigurationConditionResolver<C> conditionResolver;
protected final ReflectionConfigurationParserDelegate<C, T> delegate;
protected final String combinedFileKey;
private final boolean printMissingElements;

public ReflectionConfigurationParser(ConfigurationConditionResolver<C> conditionResolver, ReflectionConfigurationParserDelegate<C, T> delegate, boolean strictConfiguration,
boolean printMissingElements) {
boolean printMissingElements, String combinedFileKey) {
super(strictConfiguration);
this.conditionResolver = conditionResolver;
this.printMissingElements = printMissingElements;
this.delegate = delegate;
this.combinedFileKey = combinedFileKey;
}

public static <C, T> ReflectionConfigurationParser<C, T> create(String combinedFileKey, boolean strictMetadata,
Expand All @@ -76,8 +78,8 @@ protected void parseClassArray(List<Object> classes) {
protected abstract void parseClass(EconomicMap<String, Object> data);

protected void registerIfNotDefault(EconomicMap<String, Object> data, boolean defaultValue, T clazz, String propertyName, Runnable register) {
if (data.containsKey(propertyName)) {
RuntimeReflectionSupport.increaseCount(false);
if (data.containsKey(propertyName) && delegate.getClass().getName().contains("ReflectionRegistryAdapter")) {
RuntimeReflectionSupport.increaseCount(combinedFileKey.equals(REFLECTION_KEY));
}
if (data.containsKey(propertyName) ? asBoolean(data.get(propertyName), propertyName) : defaultValue) {
try {
Expand All @@ -96,7 +98,9 @@ protected void parseFields(C condition, List<Object> fields, T clazz) {

private void parseField(C condition, EconomicMap<String, Object> data, T clazz) {
checkAttributes(data, "reflection field descriptor object", Collections.singleton("name"), Arrays.asList("allowWrite", "allowUnsafeAccess"));
RuntimeReflectionSupport.increaseCount(false);
if (delegate.getClass().getName().contains("ReflectionRegistryAdapter")) {
RuntimeReflectionSupport.increaseCount(combinedFileKey.equals(REFLECTION_KEY));
}
String fieldName = asString(data.get("name"), "name");
boolean allowWrite = data.containsKey("allowWrite") && asBoolean(data.get("allowWrite"), "allowWrite");

Expand All @@ -117,7 +121,9 @@ protected void parseMethods(C condition, boolean queriedOnly, List<Object> metho

private void parseMethod(C condition, boolean queriedOnly, EconomicMap<String, Object> data, T clazz) {
checkAttributes(data, "reflection method descriptor object", Collections.singleton("name"), Collections.singleton("parameterTypes"));
RuntimeReflectionSupport.increaseCount(false);
if (delegate.getClass().getName().contains("ReflectionRegistryAdapter")) {
RuntimeReflectionSupport.increaseCount(combinedFileKey.equals(REFLECTION_KEY));
}
String methodName = asString(data.get("name"), "name");
List<T> methodParameterTypes = null;
Object parameterTypes = data.get("parameterTypes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ class ReflectionMetadataParser<C, T> extends ReflectionConfigurationParser<C, T>
"allDeclaredConstructors", "allPublicConstructors", "allDeclaredMethods", "allPublicMethods", "allDeclaredFields", "allPublicFields",
"methods", "fields", "unsafeAllocated");

private final String combinedFileKey;

ReflectionMetadataParser(String combinedFileKey, ConfigurationConditionResolver<C> conditionResolver, ReflectionConfigurationParserDelegate<C, T> delegate, boolean strictConfiguration,
boolean printMissingElements) {
super(conditionResolver, delegate, strictConfiguration, printMissingElements);
this.combinedFileKey = combinedFileKey;
super(conditionResolver, delegate, strictConfiguration, printMissingElements, combinedFileKey);
}

@Override
Expand All @@ -60,7 +57,9 @@ public void parseAndRegister(Object json, URI origin) {
@Override
protected void parseClass(EconomicMap<String, Object> data) {
checkAttributes(data, "reflection class descriptor object", List.of(TYPE_KEY), OPTIONAL_REFLECT_METADATA_ATTRS);
RuntimeReflectionSupport.increaseCount(false);
if (delegate.getClass().getName().contains("ReflectionRegistryAdapter")) {
RuntimeReflectionSupport.increaseCount(combinedFileKey.equals(REFLECTION_KEY));
}

Optional<ConfigurationTypeDescriptor> type = parseTypeContents(data.get(TYPE_KEY));
if (type.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.oracle.svm.hosted.jni;

import static com.oracle.svm.core.configure.ConfigurationParser.JNI_KEY;
import static com.oracle.svm.core.configure.ConfigurationParser.REFLECTION_KEY;

import java.lang.reflect.Executable;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -209,6 +210,8 @@ public void afterRegistration(AfterRegistrationAccess arg) {
ClassInitializationSupport.singleton());
ReflectionConfigurationParser<ConfigurationCondition, Class<?>> parser = ConfigurationParserUtils.create(JNI_KEY, true, conditionResolver, runtimeSupport, null, access.getImageClassLoader());
loadedConfigurations = ConfigurationParserUtils.parseAndRegisterConfigurationsFromCombinedFile(parser, access.getImageClassLoader(), "JNI");
ReflectionConfigurationParser<ConfigurationCondition, Class<?>> reflectParser = ConfigurationParserUtils.create(REFLECTION_KEY, true, conditionResolver, runtimeSupport, null, access.getImageClassLoader());
loadedConfigurations += ConfigurationParserUtils.parseAndRegisterConfigurationsFromCombinedFile(reflectParser, access.getImageClassLoader(), "Reflection");
ReflectionConfigurationParser<ConfigurationCondition, Class<?>> legacyParser = ConfigurationParserUtils.create(null, false, conditionResolver, runtimeSupport, null,
access.getImageClassLoader());
loadedConfigurations += ConfigurationParserUtils.parseAndRegisterConfigurations(legacyParser, access.getImageClassLoader(), "JNI",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.hosted.reflect;

import static com.oracle.svm.core.configure.ConfigurationParser.JNI_KEY;
import static com.oracle.svm.core.configure.ConfigurationParser.REFLECTION_KEY;

import java.lang.invoke.MethodHandle;
Expand Down Expand Up @@ -283,6 +284,9 @@ public void duringSetup(DuringSetupAccess a) {
ReflectionConfigurationParser<ConfigurationCondition, Class<?>> parser = ConfigurationParserUtils.create(REFLECTION_KEY, true, conditionResolver, reflectionData, proxyRegistry,
access.getImageClassLoader());
loadedConfigurations = ConfigurationParserUtils.parseAndRegisterConfigurationsFromCombinedFile(parser, access.getImageClassLoader(), "reflection");
ReflectionConfigurationParser<ConfigurationCondition, Class<?>> jniParser = ConfigurationParserUtils.create(JNI_KEY, true, conditionResolver, reflectionData, proxyRegistry,
access.getImageClassLoader());
loadedConfigurations += ConfigurationParserUtils.parseAndRegisterConfigurationsFromCombinedFile(jniParser, access.getImageClassLoader(), "JNI");
ReflectionConfigurationParser<ConfigurationCondition, Class<?>> legacyParser = ConfigurationParserUtils.create(null, false, conditionResolver, reflectionData, proxyRegistry,
access.getImageClassLoader());
loadedConfigurations += ConfigurationParserUtils.parseAndRegisterConfigurations(legacyParser, access.getImageClassLoader(), "reflection",
Expand Down

0 comments on commit 1d0c403

Please sign in to comment.