# HG changeset patch # User Christian Humer # Date 1420417867 -3600 # Node ID 15fe16c45d64da98dbad1611314608c709355fa7 # Parent 2c669386b5d017dc62fe32aab8363fe191c0c546 Truffle-DSL: changed specialization class naming scheme to use method name. This usually leads to shorter specialization class names. diff -r 2c669386b5d0 -r 15fe16c45d64 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/LazyClassLoadingTest.java --- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/LazyClassLoadingTest.java Fri Jan 02 14:31:51 2015 +0100 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/LazyClassLoadingTest.java Mon Jan 05 01:31:07 2015 +0100 @@ -44,28 +44,28 @@ Assert.assertFalse(isLoaded(nodeName + "$UninitializedNode")); Assert.assertFalse(isLoaded(nodeName + "$BaseNode")); - Assert.assertFalse(isLoaded(nodeName + "$IntNode")); - Assert.assertFalse(isLoaded(nodeName + "$BooleanNode")); + Assert.assertFalse(isLoaded(nodeName + "$DoInt0Node")); + Assert.assertFalse(isLoaded(nodeName + "$DoBoolean0Node")); Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode")); TestRootNode root = TestHelper.createRoot(factory); Assert.assertTrue(isLoaded(nodeName + "$BaseNode")); Assert.assertTrue(isLoaded(nodeName + "$UninitializedNode")); - Assert.assertFalse(isLoaded(nodeName + "$IntNode")); - Assert.assertFalse(isLoaded(nodeName + "$BooleanNode")); + Assert.assertFalse(isLoaded(nodeName + "$DoInt0Node")); + Assert.assertFalse(isLoaded(nodeName + "$DoBoolean0Node")); Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode")); Assert.assertEquals(42, TestHelper.executeWith(root, 42)); - Assert.assertTrue(isLoaded(nodeName + "$IntNode")); - Assert.assertFalse(isLoaded(nodeName + "$BooleanNode")); + Assert.assertTrue(isLoaded(nodeName + "$DoInt0Node")); + Assert.assertFalse(isLoaded(nodeName + "$DoBoolean0Node")); Assert.assertFalse(isLoaded(nodeName + "$PolymorphicNode")); Assert.assertEquals(true, TestHelper.executeWith(root, true)); - Assert.assertTrue(isLoaded(nodeName + "$IntNode")); - Assert.assertTrue(isLoaded(nodeName + "$BooleanNode")); + Assert.assertTrue(isLoaded(nodeName + "$DoInt0Node")); + Assert.assertTrue(isLoaded(nodeName + "$DoBoolean0Node")); Assert.assertTrue(isLoaded(nodeName + "$PolymorphicNode")); } @@ -85,12 +85,12 @@ abstract static class TestNode extends ValueNode { @Specialization - int s(int a) { + int doInt(int a) { return a; } @Specialization - boolean s(boolean a) { + boolean doBoolean(boolean a) { return a; } diff -r 2c669386b5d0 -r 15fe16c45d64 graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NameDuplicationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NameDuplicationTest.java Mon Jan 05 01:31:07 2015 +0100 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.api.dsl.test; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; + +public class NameDuplicationTest { + + @NodeChild + abstract static class Test0 extends ValueNode { + + @Specialization + int base(int a) { + return a; + } + + } + + @NodeChild + abstract static class Test1 extends ValueNode { + + @Specialization + int generic(int a) { + return a; + } + + } + + @NodeChild + abstract static class Test2 extends ValueNode { + + @Specialization + int polymorphic(int a) { + return a; + } + + } + + @NodeChild + abstract static class Test3 extends ValueNode { + + @Specialization + int uninitialized(int a) { + return a; + } + + } + + abstract static class AddNode extends ValueNode { + + @Specialization + int add() { + return 0; + } + + } + +} diff -r 2c669386b5d0 -r 15fe16c45d64 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java Fri Jan 02 14:31:51 2015 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java Mon Jan 05 01:31:07 2015 +0100 @@ -52,6 +52,8 @@ private static final String FRAME_VALUE = "frameValue"; + private static final String NAME_SUFFIX = "_"; + private final ProcessorContext context; private final NodeData node; private final TypeSystemData typeSystem; @@ -83,7 +85,7 @@ } private static String specializationTypeName(SpecializationData specialization) { - return specialization.getId() + "Node"; + return specialization.getId() + "Node_"; } private static TypeMirror specializationType(SpecializationData specialization) { @@ -91,23 +93,23 @@ } private static String polymorphicTypeProfileFieldName(NodeExecutionData execution) { - return execution.getName() + "Type_"; + return execution.getName() + "Type" + NAME_SUFFIX; } private static String nodeFieldName(NodeExecutionData execution) { - return execution.getName() + "_"; + return execution.getName() + NAME_SUFFIX; } private static String specializationStartFieldName() { - return "specialization_"; + return "specialization" + NAME_SUFFIX; } private static String excludedFieldName(SpecializationData specialization) { - return "exclude" + specialization.getId() + "_"; + return "exclude" + specialization.getId() + NAME_SUFFIX; } private static String executeChildMethodName(NodeExecutionData execution, TypeData type) { - return "execute" + ElementUtils.firstLetterUpperCase(execution.getName()) + (type.isGeneric() ? "" : getTypeId(type.getBoxedType())) + "_"; + return "execute" + ElementUtils.firstLetterUpperCase(execution.getName()) + (type.isGeneric() ? "" : getTypeId(type.getBoxedType())) + NAME_SUFFIX; } private static CodeTree accessParent(String name) { @@ -309,7 +311,7 @@ // create specialization private CodeTypeElement createBaseSpecialization(CodeTypeElement parentClass) { - CodeTypeElement clazz = createClass(node, null, modifiers(PRIVATE, STATIC, ABSTRACT), "BaseNode", TypeSystemNodeFactory.nodeType(typeSystem)); + CodeTypeElement clazz = createClass(node, null, modifiers(PRIVATE, ABSTRACT, STATIC), "BaseNode_", TypeSystemNodeFactory.nodeType(typeSystem)); clazz.addOptional(createSpecializationConstructor(clazz, null, null)); clazz.add(new CodeVariableElement(modifiers(PROTECTED, FINAL), nodeType(node), "root")); diff -r 2c669386b5d0 -r 15fe16c45d64 graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java --- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java Fri Jan 02 14:31:51 2015 +0100 +++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java Mon Jan 05 01:31:07 2015 +0100 @@ -597,27 +597,8 @@ } } - List needsId = new ArrayList<>(); - for (SpecializationData specialization : node.getSpecializations()) { - if (specialization.isFallback()) { - specialization.setId("Generic"); - } else if (specialization.isUninitialized()) { - specialization.setId("Uninitialized"); - } else if (specialization.isPolymorphic()) { - specialization.setId("Polymorphic"); - } else if (specialization.isSpecialized()) { - needsId.add(specialization); - } else { - throw new AssertionError(); - } - } - // verify specialization parameter length - List ids = initializeSpecializationIds(needsId); - for (int i = 0; i < ids.size(); i++) { - needsId.get(i).setId(ids.get(i)); - } - + initializeSpecializationIdsWithMethodNames(node.getSpecializations()); } private static void initializeOrder(NodeData node) { @@ -806,91 +787,34 @@ } } - private static List initializeSpecializationIds(List specializations) { - int lastSize = -1; - List> signatureChunks = new ArrayList<>(); - for (SpecializationData other : specializations) { - if (!other.isSpecialized()) { - continue; - } - List paramIds = new LinkedList<>(); - paramIds.add(ElementUtils.getTypeId(other.getReturnType().getType())); - for (Parameter param : other.getParameters()) { - if (param.getSpecification().getExecution() == null) { - continue; + private static void initializeSpecializationIdsWithMethodNames(List specializations) { + List signatures = new ArrayList<>(); + for (SpecializationData specialization : specializations) { + if (specialization.isFallback()) { + signatures.add("Fallback"); + } else if (specialization.isUninitialized()) { + signatures.add("Uninitialized"); + } else if (specialization.isPolymorphic()) { + signatures.add("Polymorphic"); + } else { + String name = specialization.getMethodName(); + + // hack for name clashes with BaseNode. + if (name.equalsIgnoreCase("base")) { + name = name + "0"; } - paramIds.add(ElementUtils.getTypeId(param.getType())); - } - assert lastSize == -1 || lastSize == paramIds.size(); - if (lastSize != -1 && lastSize != paramIds.size()) { - throw new AssertionError(); - } - signatureChunks.add(paramIds); - lastSize = paramIds.size(); - } - // reduce id vertically - for (int i = 0; i < lastSize; i++) { - String prev = null; - boolean allSame = true; - for (List signature : signatureChunks) { - String arg = signature.get(i); - if (prev == null) { - prev = arg; - continue; - } else if (!prev.equals(arg)) { - allSame = false; - break; - } - prev = arg; - } - - if (allSame) { - for (List signature : signatureChunks) { - signature.remove(i); - } - lastSize--; + signatures.add(ElementUtils.firstLetterUpperCase(name)); } } - // reduce id horizontally - for (List signature : signatureChunks) { - if (signature.isEmpty()) { - continue; - } - String prev = null; - boolean allSame = true; - for (String arg : signature) { - if (prev == null) { - prev = arg; - continue; - } else if (!prev.equals(arg)) { - allSame = false; - break; - } - prev = arg; - } + renameDuplicateIds(signatures); + for (int i = 0; i < specializations.size(); i++) { + specializations.get(i).setId(signatures.get(i)); + } + } - if (allSame) { - signature.clear(); - signature.add(prev); - } - } - - // create signatures - List signatures = new ArrayList<>(); - for (List signatureChunk : signatureChunks) { - StringBuilder b = new StringBuilder(); - if (signatureChunk.isEmpty()) { - b.append("Default"); - } else { - for (String s : signatureChunk) { - b.append(s); - } - } - signatures.add(b.toString()); - } - + private static void renameDuplicateIds(List signatures) { Map counts = new HashMap<>(); for (String s1 : signatures) { Integer count = counts.get(s1); @@ -914,8 +838,6 @@ } } } - - return signatures; } private void initializeGuards(List elements, NodeData node) {