Mercurial > hg > graal-compiler
diff graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java @ 17154:7716c6993546
Stamp: interface types can not be trusted except after explicit runtime checks
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 18 Sep 2014 17:41:19 +0200 |
parents | 4d3008ddb5a0 |
children | ac6e25901d62 |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java Thu Sep 18 23:19:03 2014 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/StampFactory.java Thu Sep 18 17:41:19 2014 +0200 @@ -224,19 +224,48 @@ } public static Stamp declared(ResolvedJavaType type, boolean nonNull) { - return object(type, false, nonNull); + return object(type, false, nonNull, false); + } + + public static Stamp declaredNonNull(ResolvedJavaType type, boolean trustInterfaces) { + return declared(type, true, trustInterfaces); + } + + public static Stamp declared(ResolvedJavaType type, boolean nonNull, boolean trustInterfaces) { + return object(type, false, nonNull, trustInterfaces); } - public static Stamp object(ResolvedJavaType type, boolean exactType, boolean nonNull) { + private static ResolvedJavaType filterInterfaceTypesOut(ResolvedJavaType type) { + if (type.isArray()) { + ResolvedJavaType componentType = filterInterfaceTypesOut(type.getComponentType()); + if (componentType != null) { + return componentType.getArrayClass(); + } + return type.getSuperclass().getArrayClass(); // arrayType.getSuperClass() == Object type + } + if (type.isInterface()) { + return null; + } + return type; + } + + public static Stamp object(ResolvedJavaType type, boolean exactType, boolean nonNull, boolean trustInterfaces) { assert type != null; assert type.getKind() == Kind.Object; - ResolvedJavaType exact = type.asExactType(); + ResolvedJavaType trustedtype; + if (!trustInterfaces) { + trustedtype = filterInterfaceTypesOut(type); + assert !exactType || trustedtype.equals(type); + } else { + trustedtype = type; + } + ResolvedJavaType exact = trustedtype != null ? trustedtype.asExactType() : null; if (exact != null) { - assert !exactType || type.equals(exact); + assert !exactType || trustedtype.equals(exact); return new ObjectStamp(exact, true, nonNull, false); - } else { - return new ObjectStamp(type, exactType, nonNull, false); } + assert !exactType || AbstractObjectStamp.isConcreteType(trustedtype); + return new ObjectStamp(trustedtype, exactType, nonNull, false); } public static Stamp exactNonNull(ResolvedJavaType type) {