Skip to content

Commit

Permalink
[GR-19268] PhysicalMemorySupportImpl needs to be added on whitelist o…
Browse files Browse the repository at this point in the history
…n Linux platform.
  • Loading branch information
tzezula committed Oct 30, 2019
1 parent f426cf3 commit 530a28f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -44,6 +45,7 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.Signature;
import org.graalvm.nativeimage.Platforms;

final class WhiteListParser extends ConfigurationParser {

Expand Down Expand Up @@ -88,32 +90,36 @@ private void parseClass(Map<String, Object> data) {
}
String className = castProperty(classObject, String.class, "name");

AnalysisType clazz = resolve(className);
if (clazz == null) {
throw new JSONParserException("Class " + className + " not found");
}
try {
AnalysisType clazz = resolve(className);
if (clazz == null) {
throw new JSONParserException("Class " + className + " not found");
}

for (Map.Entry<String, Object> entry : data.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue();
if (name.equals("name")) {
/* Already handled. */
} else if (name.equals("justification")) {
/* Used only to document the whitelist file. */
} else if (name.equals("allDeclaredConstructors")) {
if (castProperty(value, Boolean.class, "allDeclaredConstructors")) {
registerDeclaredConstructors(clazz);
}
} else if (name.equals("allDeclaredMethods")) {
if (castProperty(value, Boolean.class, "allDeclaredMethods")) {
registerDeclaredMethods(clazz);
for (Map.Entry<String, Object> entry : data.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue();
if (name.equals("name")) {
/* Already handled. */
} else if (name.equals("justification")) {
/* Used only to document the whitelist file. */
} else if (name.equals("allDeclaredConstructors")) {
if (castProperty(value, Boolean.class, "allDeclaredConstructors")) {
registerDeclaredConstructors(clazz);
}
} else if (name.equals("allDeclaredMethods")) {
if (castProperty(value, Boolean.class, "allDeclaredMethods")) {
registerDeclaredMethods(clazz);
}
} else if (name.equals("methods")) {
parseMethods(castList(value, "Attribute 'methods' must be an array of method descriptors"), clazz);
} else {
throw new JSONParserException("Unknown attribute '" + name +
"' (supported attributes: allDeclaredConstructors, allDeclaredMethods, methods, justification) in defintion of class " + className);
}
} else if (name.equals("methods")) {
parseMethods(castList(value, "Attribute 'methods' must be an array of method descriptors"), clazz);
} else {
throw new JSONParserException("Unknown attribute '" + name +
"' (supported attributes: allDeclaredConstructors, allDeclaredMethods, methods, justification) in defintion of class " + className);
}
} catch (UnsupportedPlatformException unsupportedPlatform) {
// skip the type not available on active platform
}
}

Expand Down Expand Up @@ -169,26 +175,41 @@ private List<AnalysisType> parseTypes(List<Object> types) {
List<AnalysisType> result = new ArrayList<>();
for (Object type : types) {
String typeName = castProperty(type, String.class, "types");
AnalysisType clazz = resolve(typeName);
if (clazz == null) {
throw new JSONParserException("Class " + typeName + " not found");
try {
AnalysisType clazz = resolve(typeName);
if (clazz == null) {
throw new JSONParserException("Parameter type " + typeName + " not found");
}
result.add(clazz);
} catch (UnsupportedPlatformException unsupportedPlatform) {
throw new JSONParserException("Parameter type " + typeName + " is not available on active platform");
}
result.add(clazz);
}
return result;
}

private AnalysisType resolve(String type) {
private AnalysisType resolve(String type) throws UnsupportedPlatformException {
String useType;
if (type.indexOf('[') != -1) {
useType = MetaUtil.internalNameToJava(MetaUtil.toInternalName(type), true, true);
} else {
useType = type;
}
Class<?> clz = imageClassLoader.findClassByName(useType, false);
verifySupportedOnActivePlatform(clz);
return bigBang.forClass(clz);
}

private void verifySupportedOnActivePlatform(Class<?> clz) throws UnsupportedPlatformException {
Class<?> current = clz;
do {
if (!bigBang.getUniverse().platformSupported(current)) {
throw new UnsupportedPlatformException(current);
}
current = current.getEnclosingClass();
} while (current != null);
}

private boolean registerMethod(AnalysisType type, String methodName, List<AnalysisType> formalParameters) {
Predicate<ResolvedJavaMethod> p = (m) -> methodName.equals(m.getName());
p = p.and(new SignaturePredicate(type, formalParameters, bigBang));
Expand Down Expand Up @@ -280,4 +301,13 @@ public boolean test(ResolvedJavaMethod t) {
}
}

@SuppressWarnings("serial")
private static final class UnsupportedPlatformException extends Exception {

UnsupportedPlatformException(Class<?> clazz) {
super(String.format("The %s is supported only on platforms: %s",
clazz.getName(),
Arrays.toString(clazz.getAnnotation(Platforms.class).value())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,14 @@
"byte[]"
]}
]
},
{
"name" : "com.oracle.svm.core.posix.linux.LinuxPhysicalMemory$PhysicalMemorySupportImpl",
"methods" : [
{ "name" : "sizeFromCGroup",
"justification" : "Native application on Linux determines heap size by reading /sys/fs/cgroup/memory/memory.limit_in_bytes at start.",
"parameterTypes" : [
]}
]
}
]

0 comments on commit 530a28f

Please sign in to comment.