< prev index next >

test/testlibrary/jittester/src/jdk/test/lib/jittester/IRNode.java

Print this page




  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.test.lib.jittester;
  25 
  26 // Production is base class for all elements of the IR-tree.
  27 import java.util.ArrayList;
  28 import java.util.Collection;
  29 import java.util.List;
  30 import java.util.Objects;
  31 import jdk.test.lib.jittester.loops.For;
  32 import jdk.test.lib.jittester.loops.DoWhile;
  33 import jdk.test.lib.jittester.loops.While;
  34 import jdk.test.lib.jittester.types.TypeKlass;
  35 import jdk.test.lib.jittester.visitors.Visitor;
  36 
  37 public abstract class IRNode {
  38     private IRNode parent;
  39     private final List<IRNode> children = new ArrayList<>();
  40     protected IRNode klass;
  41     protected int level;










  42     //TODO
  43     //private boolean isCFDeviation;
  44 
  45     public abstract <T> T accept(Visitor<T> v);
  46 
  47     public void setKlass(TypeKlass klass) {
  48         this.klass = klass;
  49         if (Objects.isNull(klass)) {
  50             System.out.println(getClass().getName() + " null");
  51             for (StackTraceElement s : Thread.currentThread().getStackTrace()) {
  52                 System.out.println(s.toString());
  53             }
  54         }
  55     }
  56 
  57     public void addChild(IRNode child) {

  58         children.add(child);
  59         if (!Objects.isNull(child)) {
  60             child.parent = this;
  61         }
  62     }
  63 
  64     public void addChildren(List<? extends IRNode> ch) {
  65         if (!Objects.isNull(ch)) {
  66             children.addAll(ch);
  67             for (IRNode c : ch) {
  68                 if (!Objects.isNull(c)) {
  69                     c.parent = this;
  70                 }
  71             }
  72         }
  73     }
  74 
  75     public List<IRNode> getChildren() {
  76         return children;
  77     }
  78 
  79     public IRNode getChild(int i) {
  80         return i < children.size() ? children.get(i) : null;
  81     }
  82 
  83     public IRNode getKlass() {
  84         return klass;
  85     }
  86 
  87     public IRNode getParent() {
  88         return parent;
  89     }
  90 
  91     public void setChild(int index, IRNode child) {
  92         children.set(index, child);
  93         if (!Objects.isNull(child)) {
  94             child.parent = this;
  95         }
  96     }
  97 
  98     public boolean removeChild(IRNode l) {
  99         return children.remove(l);
 100     }
 101 
 102     public boolean removeSelf() {
 103         return parent.children.remove(this);
 104     }
 105 
 106     public void resizeUpChildren(int size) {
 107         for (int i = children.size(); i < size; ++i) {
 108             children.add(null);
 109         }
 110     }
 111 
 112     public void removeAllChildren() {
 113         children.clear();


 128         children.stream()
 129                 .filter(ch -> !Objects.isNull(ch))
 130                 .forEach(ch -> sb.append(ch.getTreeTextView(indent + 1)));
 131         return sb.toString();
 132     }
 133 
 134     protected IRNode evolve() {
 135         throw new Error("Not implemented");
 136     }
 137 
 138     public int getLevel() {
 139         return level;
 140     }
 141 
 142     public long complexity() {
 143         return 0L;
 144     }
 145 
 146     @Override
 147     public final String toString() {
 148         throw new Error("Should be toJavaCode");
 149     }
 150 
 151     public String getName() {
 152         return this.getClass().getName();
 153     }
 154 
 155     public static long countDepth(Collection<IRNode> input) {
 156         return input.stream()
 157                 .filter(c -> !Objects.isNull(c))
 158                 .mapToLong(IRNode::countDepth)
 159                 .max().orElse(0L);
 160     }
 161 
 162     public long countDepth() {
 163         return IRNode.countDepth(children);
 164     }
 165 
 166     public List<IRNode> getStackableLeaves() {
 167         List<IRNode> result = new ArrayList<>();
 168         children.stream()
 169                 .filter(c -> !Objects.isNull(c))
 170                 .forEach(c -> {
 171                     if (countDepth() == c.level && (c instanceof Block)) {
 172                         result.add(c);
 173                     } else {
 174                         result.addAll(c.getStackableLeaves());
 175                     }
 176                 });
 177         return result;
 178     }
 179 
 180     public List<IRNode> getDeviantBlocks(long depth) {
 181         List<IRNode> result = new ArrayList<>();
 182         children.stream()
 183                 .filter(c -> !Objects.isNull(c))
 184                 .forEach(c -> {
 185             if (depth == c.level && c.isCFDeviation()) {
 186                         result.add(c);
 187                     } else {
 188                         result.addAll(c.getDeviantBlocks(depth));
 189                     }


  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.test.lib.jittester;
  25 
  26 // Production is base class for all elements of the IR-tree.
  27 import java.util.ArrayList;
  28 import java.util.Collection;
  29 import java.util.List;
  30 import java.util.Objects;
  31 import jdk.test.lib.jittester.loops.For;
  32 import jdk.test.lib.jittester.loops.DoWhile;
  33 import jdk.test.lib.jittester.loops.While;
  34 import jdk.test.lib.jittester.types.TypeKlass;
  35 import jdk.test.lib.jittester.visitors.Visitor;
  36 
  37 public abstract class IRNode {
  38     private IRNode parent;
  39     private final List<IRNode> children = new ArrayList<>();
  40     protected TypeKlass owner;
  41     protected int level;
  42     private final Type resultType;
  43 
  44     protected IRNode(Type resultType) {
  45         this.resultType = resultType;
  46     }
  47 
  48     public Type getResultType() {
  49         return resultType;
  50     }
  51 
  52     //TODO
  53     //private boolean isCFDeviation;
  54 
  55     public abstract <T> T accept(Visitor<T> v);
  56 
  57     public void setOwner(TypeKlass owner) {
  58         this.owner = owner;
  59         if (Objects.isNull(owner)) {
  60             System.out.println(getClass().getName() + " null");
  61             for (StackTraceElement s : Thread.currentThread().getStackTrace()) {
  62                 System.out.println(s.toString());
  63             }
  64         }
  65     }
  66 
  67     public void addChild(IRNode child) {
  68         if (Objects.nonNull(child)) {
  69             children.add(child);

  70             child.parent = this;
  71         }
  72     }
  73 
  74     public void addChildren(List<? extends IRNode> ch) {
  75         if (Objects.nonNull(ch)) {
  76             ch.stream()
  77                 .filter(c -> c != null)
  78                 .forEach(this::addChild);



  79         }
  80     }
  81 
  82     public List<IRNode> getChildren() {
  83         return children;
  84     }
  85 
  86     public IRNode getChild(int i) {
  87         return i < children.size() ? children.get(i) : null;
  88     }
  89 
  90     public TypeKlass getOwner() {
  91         return owner;
  92     }
  93 
  94     public IRNode getParent() {
  95         return parent;
  96     }
  97 
  98     public void setChild(int index, IRNode child) {
  99         children.set(index, child);
 100         if (Objects.nonNull(child)) {
 101             child.parent = this;
 102         }
 103     }
 104 
 105     public boolean removeChild(IRNode l) {
 106         return children.remove(l);
 107     }
 108 
 109     public boolean removeSelf() {
 110         return parent.children.remove(this);
 111     }
 112 
 113     public void resizeUpChildren(int size) {
 114         for (int i = children.size(); i < size; ++i) {
 115             children.add(null);
 116         }
 117     }
 118 
 119     public void removeAllChildren() {
 120         children.clear();


 135         children.stream()
 136                 .filter(ch -> !Objects.isNull(ch))
 137                 .forEach(ch -> sb.append(ch.getTreeTextView(indent + 1)));
 138         return sb.toString();
 139     }
 140 
 141     protected IRNode evolve() {
 142         throw new Error("Not implemented");
 143     }
 144 
 145     public int getLevel() {
 146         return level;
 147     }
 148 
 149     public long complexity() {
 150         return 0L;
 151     }
 152 
 153     @Override
 154     public final String toString() {
 155         return getName();
 156     }
 157 
 158     public String getName() {
 159         return this.getClass().getName();
 160     }
 161 
 162     public static long countDepth(Collection<IRNode> input) {
 163         return input.stream()
 164                 .filter(Objects::nonNull)
 165                 .mapToLong(IRNode::countDepth)
 166                 .max().orElse(0L);
 167     }
 168 
 169     public long countDepth() {
 170         return IRNode.countDepth(children);
 171     }
 172 
 173     public List<IRNode> getStackableLeaves() {
 174         List<IRNode> result = new ArrayList<>();
 175         children.stream()
 176                 .filter(Objects::nonNull)
 177                 .forEach(c -> {
 178                     if (countDepth() == c.level && (c instanceof Block)) {
 179                         result.add(c);
 180                     } else {
 181                         result.addAll(c.getStackableLeaves());
 182                     }
 183                 });
 184         return result;
 185     }
 186 
 187     public List<IRNode> getDeviantBlocks(long depth) {
 188         List<IRNode> result = new ArrayList<>();
 189         children.stream()
 190                 .filter(c -> !Objects.isNull(c))
 191                 .forEach(c -> {
 192             if (depth == c.level && c.isCFDeviation()) {
 193                         result.add(c);
 194                     } else {
 195                         result.addAll(c.getDeviantBlocks(depth));
 196                     }
< prev index next >