# HG changeset patch # User Doug Simon # Date 1411389068 -7200 # Node ID 63870b298b390d017d534473ecd8d576e02e84de # Parent 2cb007e99ed062bc62f47c00d064a411557f3db0 added timers for NodeClass creation diff -r 2cb007e99ed0 -r 63870b298b39 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Mon Sep 22 14:26:49 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Mon Sep 22 14:31:08 2014 +0200 @@ -51,7 +51,15 @@ private static final Object GetNodeClassLock = new Object(); - private static final DebugTimer NodeClassCreation = Debug.timer("NodeClassCreation"); + // Timers for creation of a NodeClass instance + private static final DebugTimer Init = Debug.timer("NodeClass.Init"); + private static final DebugTimer Init_PositionFieldOrderLoad = Debug.timer("NodeClass.Init.PositionFieldOrderLoad"); + private static final DebugTimer Init_PositionFieldOrderSort = Debug.timer("NodeClass.Init.PositionFieldOrderSort"); + private static final DebugTimer Init_FieldScanning = Debug.timer("NodeClass.Init.FieldScanning"); + private static final DebugTimer Init_Offsets = Debug.timer("NodeClass.Init.Offsets"); + private static final DebugTimer Init_Naming = Debug.timer("NodeClass.Init.Naming"); + private static final DebugTimer Init_AllowedUsages = Debug.timer("NodeClass.Init.AllowedUsages"); + private static final DebugTimer Init_IterableIds = Debug.timer("NodeClass.Init.IterableIds"); /** * Gets the {@link NodeClass} associated with a given {@link Class}. @@ -67,7 +75,7 @@ // The creation of a NodeClass must be serialized as the NodeClass constructor accesses // both FieldIntrospection.allClasses and NodeClass.nextIterableId. synchronized (GetNodeClassLock) { - try (TimerCloseable t = NodeClassCreation.start()) { + try (TimerCloseable t = Init.start()) { value = (NodeClass) allClasses.get(key); if (value == null) { GeneratedNode gen = c.getAnnotation(GeneratedNode.class); @@ -144,7 +152,10 @@ } /** - * Defines the order of fields in a node class that accessed via {@link Position}s. + * Defines the order of fields in a node class accessed via {@link Position}s. + * + * This is required so that field positions are consistent in a configuration that mixes + * (runtime) field offsets with (annotation processing time) field iterators. */ public interface PositionFieldOrder { /** @@ -162,16 +173,19 @@ return new long[0]; } if (pfo != null) { - List fields = Arrays.asList(pfo.getOrderedFieldNames(input)); - long[] offsets = new long[fields.size()]; - assert list1.size() + list2.size() == fields.size(); - for (Map.Entry e : names.entrySet()) { - int index = fields.indexOf(e.getValue()); - if (index != -1) { - offsets[index] = e.getKey(); + try (TimerCloseable t = Init_PositionFieldOrderSort.start()) { + + List fields = Arrays.asList(pfo.getOrderedFieldNames(input)); + long[] offsets = new long[fields.size()]; + assert list1.size() + list2.size() == fields.size(); + for (Map.Entry e : names.entrySet()) { + int index = fields.indexOf(e.getValue()); + if (index != -1) { + offsets[index] = e.getKey(); + } } + return offsets; } - return offsets; } return sortedLongCopy(list1, list2); } @@ -188,30 +202,34 @@ this.isSimplifiable = Simplifiable.class.isAssignableFrom(clazz); FieldScanner scanner = new FieldScanner(calcOffset); - scanner.scan(clazz); - - directInputCount = scanner.inputOffsets.size(); + try (TimerCloseable t = Init_FieldScanning.start()) { + scanner.scan(clazz); + } - isLeafNode = scanner.inputOffsets.isEmpty() && scanner.inputListOffsets.isEmpty() && scanner.successorOffsets.isEmpty() && scanner.successorListOffsets.isEmpty(); + try (TimerCloseable t1 = Init_Offsets.start()) { + directInputCount = scanner.inputOffsets.size(); - PositionFieldOrder pfo = lookupPositionFieldOrder(clazz); + isLeafNode = scanner.inputOffsets.isEmpty() && scanner.inputListOffsets.isEmpty() && scanner.successorOffsets.isEmpty() && scanner.successorListOffsets.isEmpty(); - inputOffsets = sortedOffsets(true, pfo, scanner.fieldNames, scanner.inputOffsets, scanner.inputListOffsets); + PositionFieldOrder pfo = lookupPositionFieldOrder(clazz); + + inputOffsets = sortedOffsets(true, pfo, scanner.fieldNames, scanner.inputOffsets, scanner.inputListOffsets); - inputTypes = new InputType[inputOffsets.length]; - inputOptional = new boolean[inputOffsets.length]; - for (int i = 0; i < inputOffsets.length; i++) { - inputTypes[i] = scanner.types.get(inputOffsets[i]); - assert inputTypes[i] != null; - inputOptional[i] = scanner.optionalInputs.contains(inputOffsets[i]); - } - directSuccessorCount = scanner.successorOffsets.size(); - successorOffsets = sortedOffsets(false, pfo, scanner.fieldNames, scanner.successorOffsets, scanner.successorListOffsets); + inputTypes = new InputType[inputOffsets.length]; + inputOptional = new boolean[inputOffsets.length]; + for (int i = 0; i < inputOffsets.length; i++) { + inputTypes[i] = scanner.types.get(inputOffsets[i]); + assert inputTypes[i] != null; + inputOptional[i] = scanner.optionalInputs.contains(inputOffsets[i]); + } + directSuccessorCount = scanner.successorOffsets.size(); + successorOffsets = sortedOffsets(false, pfo, scanner.fieldNames, scanner.successorOffsets, scanner.successorListOffsets); - dataOffsets = sortedLongCopy(scanner.dataOffsets); - dataTypes = new Class[dataOffsets.length]; - for (int i = 0; i < dataOffsets.length; i++) { - dataTypes[i] = scanner.fieldTypes.get(dataOffsets[i]); + dataOffsets = sortedLongCopy(scanner.dataOffsets); + dataTypes = new Class[dataOffsets.length]; + for (int i = 0; i < dataOffsets.length; i++) { + dataTypes[i] = scanner.fieldTypes.get(dataOffsets[i]); + } } fieldNames = scanner.fieldNames; @@ -220,30 +238,35 @@ canGVN = Node.ValueNumberable.class.isAssignableFrom(clazz); startGVNNumber = clazz.hashCode(); - String newShortName = clazz.getSimpleName(); - if (newShortName.endsWith("Node") && !newShortName.equals("StartNode") && !newShortName.equals("EndNode")) { - newShortName = newShortName.substring(0, newShortName.length() - 4); - } String newNameTemplate = null; - NodeInfo info = clazz.getAnnotation(NodeInfo.class); - assert info != null : "missing " + NodeInfo.class.getSimpleName() + " annotation on " + clazz; - if (!info.shortName().isEmpty()) { - newShortName = info.shortName(); - } - if (!info.nameTemplate().isEmpty()) { - newNameTemplate = info.nameTemplate(); + String newShortName; + try (TimerCloseable t1 = Init_Naming.start()) { + newShortName = clazz.getSimpleName(); + if (newShortName.endsWith("Node") && !newShortName.equals("StartNode") && !newShortName.equals("EndNode")) { + newShortName = newShortName.substring(0, newShortName.length() - 4); + } + NodeInfo info = clazz.getAnnotation(NodeInfo.class); + assert info != null : "missing " + NodeInfo.class.getSimpleName() + " annotation on " + clazz; + if (!info.shortName().isEmpty()) { + newShortName = info.shortName(); + } + if (!info.nameTemplate().isEmpty()) { + newNameTemplate = info.nameTemplate(); + } } EnumSet newAllowedUsageTypes = EnumSet.noneOf(InputType.class); - Class current = clazz; - do { - NodeInfo currentInfo = current.getAnnotation(NodeInfo.class); - if (currentInfo != null) { - if (currentInfo.allowedUsageTypes().length > 0) { - newAllowedUsageTypes.addAll(Arrays.asList(currentInfo.allowedUsageTypes())); + try (TimerCloseable t1 = Init_AllowedUsages.start()) { + Class current = clazz; + do { + NodeInfo currentInfo = current.getAnnotation(NodeInfo.class); + if (currentInfo != null) { + if (currentInfo.allowedUsageTypes().length > 0) { + newAllowedUsageTypes.addAll(Arrays.asList(currentInfo.allowedUsageTypes())); + } } - } - current = current.getSuperclass(); - } while (current != Node.class); + current = current.getSuperclass(); + } while (current != Node.class); + } this.nameTemplate = newNameTemplate == null ? newShortName : newNameTemplate; this.allowedUsageTypes = newAllowedUsageTypes; this.shortName = newShortName; @@ -252,20 +275,22 @@ this.iterableId = presetIterableId; } else if (IterableNodeType.class.isAssignableFrom(clazz)) { ITERABLE_NODE_TYPES.increment(); - this.iterableId = nextIterableId++; + try (TimerCloseable t1 = Init_IterableIds.start()) { + this.iterableId = nextIterableId++; - Class superclass = clazz.getSuperclass(); - while (superclass != NODE_CLASS) { - if (IterableNodeType.class.isAssignableFrom(superclass)) { - NodeClass superNodeClass = NodeClass.get(superclass); - assert !containsId(this.iterableId, superNodeClass.iterableIds); - superNodeClass.iterableIds = Arrays.copyOf(superNodeClass.iterableIds, superNodeClass.iterableIds.length + 1); - superNodeClass.iterableIds[superNodeClass.iterableIds.length - 1] = this.iterableId; + Class superclass = clazz.getSuperclass(); + while (superclass != NODE_CLASS) { + if (IterableNodeType.class.isAssignableFrom(superclass)) { + NodeClass superNodeClass = NodeClass.get(superclass); + assert !containsId(this.iterableId, superNodeClass.iterableIds); + superNodeClass.iterableIds = Arrays.copyOf(superNodeClass.iterableIds, superNodeClass.iterableIds.length + 1); + superNodeClass.iterableIds[superNodeClass.iterableIds.length - 1] = this.iterableId; + } + superclass = superclass.getSuperclass(); } - superclass = superclass.getSuperclass(); + + this.iterableIds = new int[]{iterableId}; } - - this.iterableIds = new int[]{iterableId}; } else { this.iterableId = Node.NOT_ITERABLE; this.iterableIds = null; @@ -275,11 +300,13 @@ private PositionFieldOrder lookupPositionFieldOrder(Class clazz) throws GraalInternalError { if (USE_GENERATED_NODES && !isAbstract(clazz.getModifiers()) && !isLeafNode) { - String name = clazz.getName().replace('$', '_') + "Gen$FieldOrder"; - try { - return (PositionFieldOrder) Class.forName(name, true, getClazz().getClassLoader()).newInstance(); - } catch (Exception e) { - throw new GraalInternalError("Could not find generated class " + name + " for " + getClazz()); + try (TimerCloseable t = Init_PositionFieldOrderLoad.start()) { + String name = clazz.getName().replace('$', '_') + "Gen$FieldOrder"; + try { + return (PositionFieldOrder) Class.forName(name, true, getClazz().getClassLoader()).newInstance(); + } catch (Exception e) { + throw new GraalInternalError("Could not find generated class " + name + " for " + getClazz()); + } } } return null; @@ -345,7 +372,7 @@ * *
      *     if (node.getNodeClass().is(BeginNode.class)) { ... }
-     * 
+     *
      *     // Due to generated Node classes, the test below
      *     // is *not* the same as the test above:
      *     if (node.getClass() == BeginNode.class) { ... }