use of com.oracle.svm.configure.config.TypeConfiguration in project graal by oracle.
the class JniProcessor method processEntry.
@Override
@SuppressWarnings("fallthrough")
void processEntry(Map<String, ?> entry) {
ConfigurationCondition condition = ConfigurationCondition.alwaysTrue();
boolean invalidResult = Boolean.FALSE.equals(entry.get("result"));
if (invalidResult) {
return;
}
String function = (String) entry.get("function");
String callerClass = (String) entry.get("caller_class");
List<?> args = (List<?>) entry.get("args");
LazyValue<String> callerClassLazyValue = lazyValue(callerClass);
// Special: FindClass and DefineClass take the class in question as a string argument
if (function.equals("FindClass") || function.equals("DefineClass")) {
String lookupName = singleElement(args);
String internalName = (lookupName.charAt(0) != '[') ? ('L' + lookupName + ';') : lookupName;
String forNameString = MetaUtil.internalNameToJava(internalName, true, true);
if (!advisor.shouldIgnore(lazyValue(forNameString), callerClassLazyValue)) {
if (function.equals("FindClass")) {
configuration.getOrCreateType(condition, forNameString);
} else if (!AccessAdvisor.PROXY_CLASS_NAME_PATTERN.matcher(lookupName).matches()) {
// DefineClass
logWarning("Unsupported JNI function DefineClass used to load class " + forNameString);
}
}
return;
}
String clazz = (String) entry.get("class");
if (advisor.shouldIgnore(lazyValue(clazz), callerClassLazyValue)) {
return;
}
String declaringClass = (String) entry.get("declaring_class");
String declaringClassOrClazz = (declaringClass != null) ? declaringClass : clazz;
ConfigurationMemberDeclaration declaration = (declaringClass != null) ? ConfigurationMemberDeclaration.DECLARED : ConfigurationMemberDeclaration.PRESENT;
TypeConfiguration config = configuration;
switch(function) {
case "GetStaticMethodID":
case "GetMethodID":
{
expectSize(args, 2);
String name = (String) args.get(0);
String signature = (String) args.get(1);
if (!advisor.shouldIgnoreJniMethodLookup(lazyValue(clazz), lazyValue(name), lazyValue(signature), callerClassLazyValue)) {
config.getOrCreateType(condition, declaringClassOrClazz).addMethod(name, signature, declaration);
if (!declaringClassOrClazz.equals(clazz)) {
config.getOrCreateType(condition, clazz);
}
}
break;
}
case "GetFieldID":
case "GetStaticFieldID":
{
expectSize(args, 2);
String name = (String) args.get(0);
config.getOrCreateType(condition, declaringClassOrClazz).addField(name, declaration, false);
if (!declaringClassOrClazz.equals(clazz)) {
config.getOrCreateType(condition, clazz);
}
break;
}
case "ThrowNew":
{
// exception message, ignore
expectSize(args, 1);
String name = ConfigurationMethod.CONSTRUCTOR_NAME;
String signature = "(Ljava/lang/String;)V";
if (!advisor.shouldIgnoreJniMethodLookup(lazyValue(clazz), lazyValue(name), lazyValue(signature), callerClassLazyValue)) {
config.getOrCreateType(condition, declaringClassOrClazz).addMethod(name, signature, declaration);
assert declaringClassOrClazz.equals(clazz) : "Constructor can only be accessed via declaring class";
}
break;
}
case "ToReflectedField":
// fall through
config = reflectionConfiguration;
case "FromReflectedField":
{
expectSize(args, 1);
String name = (String) args.get(0);
config.getOrCreateType(condition, declaringClassOrClazz).addField(name, declaration, false);
break;
}
case "ToReflectedMethod":
// fall through
config = reflectionConfiguration;
case "FromReflectedMethod":
{
expectSize(args, 2);
String name = (String) args.get(0);
String signature = (String) args.get(1);
config.getOrCreateType(condition, declaringClassOrClazz).addMethod(name, signature, declaration);
break;
}
case "NewObjectArray":
{
expectSize(args, 0);
String arrayQualifiedJavaName = MetaUtil.internalNameToJava(clazz, true, true);
config.getOrCreateType(condition, arrayQualifiedJavaName);
break;
}
}
}
use of com.oracle.svm.configure.config.TypeConfiguration in project graal by oracle.
the class TypeMethodsWithFlagsTest method doTest.
void doTest() {
TypeConfiguration currentConfigWithoutPrevious = TypeConfiguration.copyAndSubtract(currentConfig, previousConfig);
String name = getTypeName();
ConfigurationType configurationType = currentConfigWithoutPrevious.get(ConfigurationCondition.alwaysTrue(), name);
if (methodsThatMustExist.size() == 0) {
Assert.assertNull("Generated configuration type " + name + " exists. Expected it to be cleared as it is empty.", configurationType);
} else {
Assert.assertNotNull("Generated configuration type " + name + " does not exist. Has the test code changed?", configurationType);
for (Map.Entry<ConfigurationMethod, ConfigurationMemberDeclaration> methodEntry : methodsThatMustExist.entrySet()) {
ConfigurationMemberDeclaration kind = ConfigurationType.TestBackdoor.getMethodInfoIfPresent(configurationType, methodEntry.getKey()).getDeclaration();
Assert.assertNotNull("Method " + methodEntry.getKey() + " unexpectedly NOT found in the new configuration.", kind);
Assert.assertEquals("Method " + methodEntry.getKey() + " contains a different kind than expected in the new configuration.", kind, methodEntry.getValue());
}
for (Map.Entry<ConfigurationMethod, ConfigurationMemberDeclaration> methodEntry : methodsThatMustNotExist.entrySet()) {
ConfigurationMemberInfo kind = ConfigurationType.TestBackdoor.getMethodInfoIfPresent(configurationType, methodEntry.getKey());
Assert.assertNull("Method " + methodEntry.getKey() + " unexpectedly found in the new configuration.", kind);
}
}
}
use of com.oracle.svm.configure.config.TypeConfiguration in project graal by oracle.
the class ConfigurationWithOriginsResultWriter method createNewTraceProcessor.
private TraceProcessor createNewTraceProcessor() {
TypeConfiguration jniConfig = new TypeConfiguration();
TypeConfiguration reflectConfig = new TypeConfiguration();
ProxyConfiguration proxyConfig = new ProxyConfiguration();
ResourceConfiguration resourceConfig = new ResourceConfiguration();
SerializationConfiguration serializationConfiguration = new SerializationConfiguration();
PredefinedClassesConfiguration predefinedClassesConfiguration = new PredefinedClassesConfiguration(new Path[0], null);
return new TraceProcessor(advisor, jniConfig, reflectConfig, proxyConfig, resourceConfig, serializationConfiguration, predefinedClassesConfiguration, null);
}
Aggregations