test/hotspot/jtreg/compiler/c2/Test6857159.java
changeset 59211 71a84cee0c39
parent 47216 71c04702a3d5
equal deleted inserted replaced
59210:78184b74af6e 59211:71a84cee0c39
     1 /*
     1 /*
     2  * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25  * @test
    25  * @test
    26  * @bug 6857159
    26  * @bug 6857159
    27  * @summary local schedule failed with checkcast of Thread.currentThread()
    27  * @summary local schedule failed with checkcast of Thread.currentThread()
    28  * @library /test/lib
    28  * @library /test/lib
    29  * @modules java.base/jdk.internal.misc
    29  * @modules java.base/jdk.internal.misc
    30  *          java.management
       
    31  *
    30  *
    32  * @run driver compiler.c2.Test6857159
    31  * @build sun.hotspot.WhiteBox
       
    32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
       
    33  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
       
    34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
       
    35  *      -Xbatch -XX:CompileCommand=compileonly,compiler.c2.Test6857159$ct0::run
       
    36  *      compiler.c2.Test6857159
    33  */
    37  */
    34 
    38 
    35 package compiler.c2;
    39 package compiler.c2;
    36 
    40 
    37 import jdk.test.lib.process.OutputAnalyzer;
    41 import sun.hotspot.WhiteBox;
    38 import jdk.test.lib.process.ProcessTools;
       
    39 
    42 
    40 public class Test6857159 {
    43 public class Test6857159 extends Thread {
    41     public static void main(String[] args) throws Throwable {
    44     public static void main(String[] args) throws Exception {
    42         String className = Test.class.getName();
    45         var whiteBox = WhiteBox.getWhiteBox();
    43         OutputAnalyzer analyzer = ProcessTools.executeTestJvm("-Xbatch",
    46         var method = ct0.class.getDeclaredMethod("run");
    44                 "-XX:+PrintCompilation",
    47         for (int i = 0; i < 20000; i++) {
    45                 "-XX:CompileOnly="+ className + "$ct::run",
    48             Thread t = null;
    46                 className);
    49             switch (i % 3) {
    47         analyzer.shouldNotContain("COMPILE SKIPPED");
    50                 case 0:
    48         analyzer.shouldContain(className + "$ct0::run (16 bytes)");
    51                     t = new ct0();
    49         analyzer.shouldHaveExitValue(0);
    52                     break;
       
    53                 case 1:
       
    54                     t = new ct1();
       
    55                     break;
       
    56                 case 2:
       
    57                     t = new ct2();
       
    58                     break;
       
    59             }
       
    60             t.start();
       
    61             t.join();
       
    62         }
       
    63         if (!whiteBox.isMethodCompiled(method)) {
       
    64             throw new AssertionError(method + " didn't get compiled");
       
    65         }
    50     }
    66     }
    51 
    67 
    52     static class Test extends Thread {
    68     static class ct0 extends Test6857159 {
    53         static class ct0 extends Test {
    69         public void message() { }
    54             public void message() {
       
    55             }
       
    56 
    70 
    57             public void run() {
    71         public void run() {
    58                 message();
    72             message();
    59                 ct0 ct = (ct0) Thread.currentThread();
    73             ct0 ct = (ct0) Thread.currentThread();
    60                 ct.message();
    74             ct.message();
    61             }
       
    62         }
       
    63 
       
    64         static class ct1 extends ct0 {
       
    65             public void message() {
       
    66             }
       
    67         }
       
    68 
       
    69         static class ct2 extends ct0 {
       
    70             public void message() {
       
    71             }
       
    72         }
       
    73 
       
    74         public static void main(String[] args) throws Exception {
       
    75             for (int i = 0; i < 20000; i++) {
       
    76                 Thread t = null;
       
    77                 switch (i % 3) {
       
    78                     case 0:
       
    79                         t = new ct0();
       
    80                         break;
       
    81                     case 1:
       
    82                         t = new ct1();
       
    83                         break;
       
    84                     case 2:
       
    85                         t = new ct2();
       
    86                         break;
       
    87                 }
       
    88                 t.start();
       
    89                 t.join();
       
    90             }
       
    91         }
    75         }
    92     }
    76     }
       
    77 
       
    78     static class ct1 extends ct0 {
       
    79         public void message() { }
       
    80     }
       
    81 
       
    82     static class ct2 extends ct0 {
       
    83         public void message() { }
       
    84     }
    93 }
    85 }