# HG changeset patch # User Doug Simon # Date 1354124897 -3600 # Node ID 4c0d132dca4d6a52bf2500f7bf1bf63322399b7e # Parent 902f60aa20cc1b2e98228c8d59bfddd06d88dc30 made HotSpotResolvedObjectType.findUniqueConcreteSubtype() more conservative for array types to fix issue with frequent invalidation of Graal compiled methods diff -r 902f60aa20cc -r 4c0d132dca4d graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TypeCheckHints.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TypeCheckHints.java Wed Nov 28 18:45:54 2012 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/TypeCheckHints.java Wed Nov 28 18:48:17 2012 +0100 @@ -22,11 +22,13 @@ */ package com.oracle.graal.api.code; -import java.lang.reflect.*; +import static com.oracle.graal.api.meta.MetaUtil.*; +import static java.lang.reflect.Modifier.*; + import java.util.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.meta.JavaTypeProfile.*; +import com.oracle.graal.api.meta.JavaTypeProfile.ProfiledType; /** * Utility for deriving hint types for a type check instruction (e.g. checkcast or instanceof) @@ -58,7 +60,7 @@ * @param maxHints the maximum length of {@link #types} */ public TypeCheckHints(ResolvedJavaType type, JavaTypeProfile profile, Assumptions assumptions, double minHintHitProbability, int maxHints) { - if (type != null && isFinalClass(type)) { + if (type != null && canHaveSubtype(type)) { types = new ResolvedJavaType[] {type}; exact = true; } else { @@ -105,15 +107,12 @@ } /** - * Determines if a given type can have subtypes. This analysis is purely static; no + * Determines if a given type can have subtypes other than itself. This analysis is purely static; no * assumptions are made. * * @return true if {@code type} has no subtype(s) */ - public static boolean isFinalClass(ResolvedJavaType type) { - if (type.isArray()) { - return isFinalClass(type.getComponentType()); - } - return Modifier.isFinal(type.getModifiers()); + public static boolean canHaveSubtype(ResolvedJavaType type) { + return isFinal(getElementalType(type).getModifiers()); } } diff -r 902f60aa20cc -r 4c0d132dca4d graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java Wed Nov 28 18:45:54 2012 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java Wed Nov 28 18:48:17 2012 +0100 @@ -181,12 +181,14 @@ * Attempts to get a unique concrete subclass of this type. *

* For an {@linkplain #isArray() array} type A, the unique concrete subclass is A if - * the element type of A is primitive or has no subtype. Otherwise there is no unique concrete subclass. + * the {@linkplain MetaUtil#getElementalType(ResolvedJavaType) elemental} type of A + * is final (which includes primitive types). Otherwise {@code null} is returned for A. *

- * For a non-array type T, the result is the unique concrete type in the complete hierarchy of T. + * For a non-array type T, the result is the unique concrete type in the current hierarchy of T. *

* A runtime may decide not to manage or walk a large hierarchy and so the result is conservative. * That is, a non-null result is guaranteed to be the unique concrete class in T's hierarchy + * at the current point in time * but a null result does not necessarily imply that there is no unique concrete class in T's hierarchy. *

* If the compiler uses the result of this method for its compilation, it must register an assumption because diff -r 902f60aa20cc -r 4c0d132dca4d graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Wed Nov 28 18:45:54 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Wed Nov 28 18:48:17 2012 +0100 @@ -160,26 +160,11 @@ return javaComponentType == null ? null : fromClass(javaComponentType); } - private static boolean hasSubtype(ResolvedJavaType type) { - assert !type.isArray() : type; - if (type.isPrimitive()) { - return false; - } - HotSpotVMConfig config = HotSpotGraalRuntime.getInstance().getConfig(); - if (unsafeReadWord(((HotSpotResolvedObjectType) type).metaspaceKlass + config.subklassOffset) != 0) { - return true; - } - return false; - } - @Override public ResolvedJavaType findUniqueConcreteSubtype() { HotSpotVMConfig config = HotSpotGraalRuntime.getInstance().getConfig(); if (isArray()) { - if (hasSubtype(getElementalType(this))) { - return null; - } - return this; + return isFinal(getElementalType(this).getModifiers()) ? this : null; } else { HotSpotResolvedObjectType type = this; while (isAbstract(type.getModifiers())) { @@ -254,7 +239,7 @@ if (isArray()) { return getComponentType().asExactType() != null ? this : null; } - return Modifier.isFinal(getModifiers()) ? this : null; + return isFinal(getModifiers()) ? this : null; } @Override @@ -402,7 +387,7 @@ fieldCache.put(id, result); } else { assert result.getName().equals(fieldName); - assert result.getModifiers() == (Modifier.fieldModifiers() & flags); + assert result.getModifiers() == (fieldModifiers() & flags); } return result; diff -r 902f60aa20cc -r 4c0d132dca4d graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Nov 28 18:45:54 2012 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Nov 28 18:48:17 2012 +0100 @@ -623,7 +623,7 @@ } private JavaTypeProfile getProfileForTypeCheck(ResolvedJavaType type) { - if (!optimisticOpts.useTypeCheckHints() || TypeCheckHints.isFinalClass(type)) { + if (!optimisticOpts.useTypeCheckHints() || TypeCheckHints.canHaveSubtype(type)) { return null; } else { ResolvedJavaType uniqueSubtype = type.findUniqueConcreteSubtype();