< prev index next >

test/langtools/tools/javac/valhalla/lworld-values/ConstantPropagationTest.java

Print this page




  39     static final __ByValue class X {
  40         static final int sfif = 8888;
  41         final int ifif = 9999;
  42         static void foo(X x) {
  43             System.out.println(sfif);
  44             System.out.println(x.ifif);
  45         }
  46     }
  47 
  48     public static void main(String[] args) {
  49         new ConstantPropagationTest().run();
  50     }
  51 
  52     void run() {
  53         String [] params = new String [] { "-v",
  54                                             Paths.get(System.getProperty("test.classes"),
  55                                                 "ConstantPropagationTest$X.class").toString() };
  56         runCheck(params, new String [] {
  57 
  58          "ConstantValue: int 8888",
  59          "0: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;",
  60          "3: sipush        8888",
  61          "6: invokevirtual #5                  // Method java/io/PrintStream.println:(I)V",
  62          "9: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;",
  63          "12: aload_0",
  64          "13: getfield      #2                  // Field ifif:I",
  65         "16: invokevirtual #5                  // Method java/io/PrintStream.println:(I)V",
  66         "19: return",
  67            
  68          }, new String [] {
  69          "ConstantValue: int 9999"
  70          });
  71 
  72      }
  73 
  74      void runCheck(String [] params, String [] expectedOut, String [] unexpectedOut) {
  75         StringWriter s;
  76         String out;
  77 
  78         try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
  79             com.sun.tools.javap.Main.run(params, pw);
  80             out = s.toString();
  81         }
  82         int errors = 0;
  83         for (String eo: expectedOut) {
  84             if (!out.contains(eo)) {
  85                 System.err.println("Match not found for string: " + eo);
  86                 errors++;
  87             }


  39     static final __ByValue class X {
  40         static final int sfif = 8888;
  41         final int ifif = 9999;
  42         static void foo(X x) {
  43             System.out.println(sfif);
  44             System.out.println(x.ifif);
  45         }
  46     }
  47 
  48     public static void main(String[] args) {
  49         new ConstantPropagationTest().run();
  50     }
  51 
  52     void run() {
  53         String [] params = new String [] { "-v",
  54                                             Paths.get(System.getProperty("test.classes"),
  55                                                 "ConstantPropagationTest$X.class").toString() };
  56         runCheck(params, new String [] {
  57 
  58          "ConstantValue: int 8888",

  59          "3: sipush        8888",







  60          }, new String [] {
  61          "ConstantValue: int 9999"
  62          });
  63 
  64      }
  65 
  66      void runCheck(String [] params, String [] expectedOut, String [] unexpectedOut) {
  67         StringWriter s;
  68         String out;
  69 
  70         try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
  71             com.sun.tools.javap.Main.run(params, pw);
  72             out = s.toString();
  73         }
  74         int errors = 0;
  75         for (String eo: expectedOut) {
  76             if (!out.contains(eo)) {
  77                 System.err.println("Match not found for string: " + eo);
  78                 errors++;
  79             }
< prev index next >