# HG changeset patch # User Doug Simon # Date 1412083567 -7200 # Node ID 9eb112c9337d5032c200602adc4fb742a54d46e6 # Parent fa3637e235b129f3b1ec9e18cf96d12fa4ac0a1f moved Node naming logic back to NodeClass (without impacting NodeClass constructor performance) diff -r fa3637e235b1 -r 9eb112c9337d graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Tue Sep 30 14:45:03 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Tue Sep 30 15:26:07 2014 +0200 @@ -782,28 +782,6 @@ return USE_GENERATED_NODES || getNodeClass().isLeafNode(); } - /** - * Gets the value used by {@link #toString(Verbosity)} to build a {@linkplain Verbosity#Name - * short} name. - */ - public String getShortName() { - String shortName = getClass().getSimpleName().toString(); - if (shortName.endsWith("Node")) { - shortName = shortName.substring(0, shortName.length() - 4); - } - return shortName; - } - - /** - * The template used to build the {@link Verbosity#Name} version. Variable parts are specified - * using {i#inputName} or {p#propertyName}. - * - * The default implementation of this method in {@link Node} returns {@code getShortName()}. - */ - public String getNameTemplate() { - return getShortName(); - } - protected void afterClone(@SuppressWarnings("unused") Node other) { } @@ -930,7 +908,7 @@ case Id: return Integer.toString(id); case Name: - return getShortName(); + return getNodeClass().shortName(); case Short: return toString(Verbosity.Id) + "|" + toString(Verbosity.Name); case Long: diff -r fa3637e235b1 -r 9eb112c9337d 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 Tue Sep 30 14:45:03 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Tue Sep 30 15:26:07 2014 +0200 @@ -128,6 +128,7 @@ private final boolean canGVN; private final int startGVNNumber; + private final String nameTemplate; private final int iterableId; private final EnumSet allowedUsageTypes; private int[] iterableIds; @@ -188,6 +189,8 @@ startGVNNumber = clazz.hashCode(); NodeInfo info = getAnnotation(clazz, NodeInfo.class); + this.nameTemplate = info.nameTemplate(); + try (TimerCloseable t1 = Init_AllowedUsages.start()) { allowedUsageTypes = superNodeClass == null ? EnumSet.noneOf(InputType.class) : superNodeClass.allowedUsageTypes.clone(); allowedUsageTypes.addAll(Arrays.asList(info.allowedUsageTypes())); @@ -271,6 +274,20 @@ return nodeClass == getClazz(); } + public String shortName() { + NodeInfo info = getAnnotation(getClazz(), NodeInfo.class); + String shortName; + if (!info.shortName().isEmpty()) { + shortName = info.shortName(); + } else { + shortName = getClazz().getSimpleName(); + if (shortName.endsWith("Node") && !shortName.equals("StartNode") && !shortName.equals("EndNode")) { + shortName = shortName.substring(0, shortName.length() - 4); + } + } + return shortName; + } + public int[] iterableIds() { nodeIterableCount.increment(); return iterableIds; @@ -696,7 +713,16 @@ return getClazz(); } + /** + * The template used to build the {@link Verbosity#Name} version. Variable parts are specified + * using {i#inputName} or {p#propertyName}. + */ + public String getNameTemplate() { + return nameTemplate.isEmpty() ? shortName() : nameTemplate; + } + interface InplaceUpdateClosure { + Node replacement(Node node, Edges.Type type); } diff -r fa3637e235b1 -r 9eb112c9337d graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java --- a/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java Tue Sep 30 14:45:03 2014 +0200 +++ b/graal/com.oracle.graal.nodeinfo.processor/src/com/oracle/graal/nodeinfo/processor/GraphNodeGenerator.java Tue Sep 30 15:26:07 2014 +0200 @@ -334,9 +334,6 @@ if (hasInputs || hasSuccessors) { createIsLeafNodeMethod(); } - - createGetShortNameMethod(node); - createGetNameTemplateMethod(node); } compilationUnit.add(genClass); return compilationUnit; @@ -423,7 +420,7 @@ List overriddenMethods = getDeclaredMethodsInSuperTypes(method.getEnclosingClass(), method.getSimpleName().toString(), method.getParameterTypes()); for (ExecutableElement overriddenMethod : overriddenMethods) { if (!overriddenMethod.getEnclosingElement().equals(Node)) { - env.message(Kind.WARNING, overriddenMethod, "This method is overridden in a generated subclass and will never be called"); + env.message(Kind.WARNING, overriddenMethod, "This method is overridden in a generated subclass will never be called"); } } } @@ -435,26 +432,6 @@ checkOnlyInGenNode(method); } - private void createGetShortNameMethod(TypeElement node) { - NodeInfo nodeInfo = node.getAnnotation(NodeInfo.class); - if (!nodeInfo.shortName().isEmpty()) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), getType(String.class), "getShortName"); - method.createBuilder().startReturn().string("\"" + nodeInfo.shortName() + "\"").end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - } - - private void createGetNameTemplateMethod(TypeElement node) { - NodeInfo nodeInfo = node.getAnnotation(NodeInfo.class); - if (!nodeInfo.nameTemplate().isEmpty()) { - CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), getType(String.class), "getNameTemplate"); - method.createBuilder().startReturn().string("\"" + nodeInfo.nameTemplate() + "\"").end(); - genClass.add(method); - checkOnlyInGenNode(method); - } - } - private boolean hidesField(String name) { for (VariableElement field : concat(inputFields, inputListFields, successorFields, successorListFields, dataFields)) { if (field.getSimpleName().contentEquals(name)) { diff -r fa3637e235b1 -r 9eb112c9337d graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java Tue Sep 30 14:45:03 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/EndNode.java Tue Sep 30 15:26:07 2014 +0200 @@ -32,12 +32,4 @@ EndNode() { } - - @Override - public String getShortName() { - if (getNodeClass().is(EndNode.class)) { - return getClass().getSimpleName(); - } - return super.getShortName(); - } } diff -r fa3637e235b1 -r 9eb112c9337d graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StartNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StartNode.java Tue Sep 30 14:45:03 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StartNode.java Tue Sep 30 15:26:07 2014 +0200 @@ -42,12 +42,4 @@ public LocationIdentity getLocationIdentity() { return LocationIdentity.ANY_LOCATION; } - - @Override - public String getShortName() { - if (getNodeClass().is(StartNode.class)) { - return getClass().getSimpleName(); - } - return super.getShortName(); - } } diff -r fa3637e235b1 -r 9eb112c9337d graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java Tue Sep 30 14:45:03 2014 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java Tue Sep 30 15:26:07 2014 +0200 @@ -231,23 +231,6 @@ } } - private void writeNodeClass(Node node, NodeClass nodeClass) throws IOException { - Character id = constantPool.get(nodeClass); - if (id == null) { - char index = constantPool.add(nodeClass); - writeByte(POOL_NEW); - writeShort(index); - writeByte(POOL_NODE_CLASS); - writeString(nodeClass.getJavaClass().getSimpleName()); - writeString(node.getNameTemplate()); - writeEdgesInfo(nodeClass, Inputs); - writeEdgesInfo(nodeClass, Successors); - } else { - writeByte(POOL_NODE_CLASS); - writeShort(id.charValue()); - } - } - private void writePoolObject(Object object) throws IOException { if (object == null) { writeByte(POOL_NULL); @@ -261,6 +244,8 @@ writeByte(POOL_ENUM); } else if (object instanceof Class || object instanceof JavaType) { writeByte(POOL_CLASS); + } else if (object instanceof NodeClass) { + writeByte(POOL_NODE_CLASS); } else if (object instanceof ResolvedJavaMethod) { writeByte(POOL_METHOD); } else if (object instanceof ResolvedJavaField) { @@ -282,7 +267,6 @@ } private void addPoolEntry(Object object) throws IOException { - assert !(object instanceof NodeClass); char index = constantPool.add(object); writeByte(POOL_NEW); writeShort(index); @@ -309,6 +293,13 @@ writeByte(POOL_CLASS); writeString(type.toJavaName()); writeByte(KLASS); + } else if (object instanceof NodeClass) { + NodeClass nodeClass = (NodeClass) object; + writeByte(POOL_NODE_CLASS); + writeString(nodeClass.getJavaClass().getSimpleName()); + writeString(nodeClass.getNameTemplate()); + writeEdgesInfo(nodeClass, Inputs); + writeEdgesInfo(nodeClass, Successors); } else if (object instanceof ResolvedJavaMethod) { writeByte(POOL_METHOD); ResolvedJavaMethod method = ((ResolvedJavaMethod) object); @@ -431,7 +422,7 @@ } } writeInt(getNodeId(node)); - writeNodeClass(node, nodeClass); + writePoolObject(nodeClass); writeByte(node.predecessor() == null ? 0 : 1); // properties writeShort((char) props.size()); diff -r fa3637e235b1 -r 9eb112c9337d graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Tue Sep 30 14:45:03 2014 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinter.java Tue Sep 30 15:26:07 2014 +0200 @@ -354,7 +354,7 @@ out.print(HOVER_END).println(COLUMN_END); out.print("instruction "); - out.print(HOVER_START).print(node.getShortName()).print(HOVER_SEP).print(node.getClass().getName()).print(HOVER_END).print(" "); + out.print(HOVER_START).print(node.getNodeClass().shortName()).print(HOVER_SEP).print(node.getClass().getName()).print(HOVER_END).print(" "); printNamedNodes(node, node.inputs().iterator(), "", "", "#NDF"); printNamedNodes(node, node.successors().iterator(), "#", "", "#NDF"); for (Map.Entry entry : props.entrySet()) {