< prev index next >

test/compiler/compilercontrol/share/scenario/JcmdStateBuilder.java

Print this page
rev 9430 : [mq]: PrintDirectives
rev 9150 : 8066166: JEP-JDK-8046155: Test task: dcmd tests
Summary: Tests for diagnostic command in CompilerControl
Reviewed-by: kvn


  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package compiler.compilercontrol.share.scenario;
  25 
  26 import compiler.compilercontrol.share.method.MethodDescriptor;
  27 import compiler.compilercontrol.share.method.MethodGenerator;
  28 import pool.PoolHelper;
  29 import jdk.test.lib.Pair;
  30 
  31 import java.lang.reflect.Executable;
  32 import java.util.ArrayList;
  33 import java.util.HashMap;
  34 import java.util.Iterator;
  35 import java.util.LinkedHashMap;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.util.concurrent.Callable;

  39 
  40 public class JcmdStateBuilder implements StateBuilder<JcmdCommand> {
  41     private static final List<Pair<Executable, Callable<?>>> METHODS
  42             = new PoolHelper().getAllMethods();
  43     private final Map<Executable, State> stateMap = new HashMap<>();
  44     private final DirectiveBuilder directiveBuilder;
  45     private Map<MethodDescriptor, List<CompileCommand>> matchBlocks
  46             = new LinkedHashMap<>();
  47     private List<JcmdCommand> commands = new ArrayList<>();
  48     private boolean isFileValid = true;
  49 
  50     public JcmdStateBuilder(String fileName) {
  51         directiveBuilder = new DirectiveBuilder(fileName);
  52     }
  53 
  54     @Override
  55     public void add(JcmdCommand compileCommand) {
  56         commands.add(compileCommand);
  57         switch (compileCommand.jcmdType) {
  58             case ADD:
  59                 directiveBuilder.add(compileCommand);
  60                 addCommand(compileCommand);
  61                 break;
  62             case PRINT:
  63                 // doesn't change the state
  64                 break;
  65             case CLEAR:
  66                 matchBlocks.clear();
  67                 break;
  68             case REMOVE:
  69                 removeDirective();
  70                 break;
  71         }
  72     }
  73 
  74     private void addCommand(JcmdCommand compileCommand) {
  75         isFileValid &= compileCommand.isValid();
  76         for (MethodDescriptor md: matchBlocks.keySet()) {


 142                             case INLINE:
 143                             case DONTINLINE:
 144                                 state.apply(cc);
 145                                 break;
 146                         }
 147                     }
 148                 }
 149                 isMatchFound = true;
 150             }
 151         }
 152         return state;
 153     }
 154 
 155     @Override
 156     public List<String> getOptions() {
 157         return new ArrayList<>();
 158     }
 159 
 160     @Override
 161     public List<JcmdCommand> getCompileCommands() {
 162         return commands;









 163     }
 164 }


  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package compiler.compilercontrol.share.scenario;
  25 
  26 import compiler.compilercontrol.share.method.MethodDescriptor;
  27 import compiler.compilercontrol.share.method.MethodGenerator;
  28 import pool.PoolHelper;
  29 import jdk.test.lib.Pair;
  30 
  31 import java.lang.reflect.Executable;
  32 import java.util.ArrayList;
  33 import java.util.HashMap;
  34 import java.util.Iterator;
  35 import java.util.LinkedHashMap;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.util.concurrent.Callable;
  39 import java.util.stream.Collectors;
  40 
  41 public class JcmdStateBuilder implements StateBuilder<JcmdCommand> {
  42     private static final List<Pair<Executable, Callable<?>>> METHODS
  43             = new PoolHelper().getAllMethods();
  44     private final Map<Executable, State> stateMap = new HashMap<>();
  45     private final DirectiveBuilder directiveBuilder;
  46     private Map<MethodDescriptor, List<CompileCommand>> matchBlocks
  47             = new LinkedHashMap<>();

  48     private boolean isFileValid = true;
  49 
  50     public JcmdStateBuilder(String fileName) {
  51         directiveBuilder = new DirectiveBuilder(fileName);
  52     }
  53 
  54     @Override
  55     public void add(JcmdCommand compileCommand) {

  56         switch (compileCommand.jcmdType) {
  57             case ADD:
  58                 directiveBuilder.add(compileCommand);
  59                 addCommand(compileCommand);
  60                 break;
  61             case PRINT:
  62                 // doesn't change the state
  63                 break;
  64             case CLEAR:
  65                 matchBlocks.clear();
  66                 break;
  67             case REMOVE:
  68                 removeDirective();
  69                 break;
  70         }
  71     }
  72 
  73     private void addCommand(JcmdCommand compileCommand) {
  74         isFileValid &= compileCommand.isValid();
  75         for (MethodDescriptor md: matchBlocks.keySet()) {


 141                             case INLINE:
 142                             case DONTINLINE:
 143                                 state.apply(cc);
 144                                 break;
 145                         }
 146                     }
 147                 }
 148                 isMatchFound = true;
 149             }
 150         }
 151         return state;
 152     }
 153 
 154     @Override
 155     public List<String> getOptions() {
 156         return new ArrayList<>();
 157     }
 158 
 159     @Override
 160     public List<JcmdCommand> getCompileCommands() {
 161         if (isFileValid) {
 162             return matchBlocks.keySet().stream()
 163                     /* only method descriptor is required
 164                        to check print_directives */
 165                     .map(md -> new JcmdCommand(null, md, null, null,
 166                             Scenario.JcmdType.ADD))
 167                     .collect(Collectors.toList());
 168         } else {
 169             return new ArrayList<>();
 170         }
 171     }
 172 }
< prev index next >