< prev index next >

test/compiler/jvmci/compilerToVM/CompileCodeTestCase.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 
  25 package compiler.jvmci.compilerToVM;
  26 

  27 import compiler.testlibrary.CompilerUtils;
  28 import jdk.test.lib.Utils;

  29 import sun.hotspot.WhiteBox;
  30 import sun.hotspot.code.NMethod;
  31 
  32 import java.lang.reflect.Executable;
  33 import java.lang.reflect.Modifier;
  34 import java.util.ArrayList;
  35 import java.util.Arrays;
  36 import java.util.Collections;
  37 import java.util.HashMap;
  38 import java.util.List;
  39 import java.util.Map;
  40 
  41 /**
  42  * A test case for tests which require compiled code.
  43  */
  44 public final class CompileCodeTestCase {
  45     public static final Map<Class<?>, Object> RECEIVERS;
  46     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  47     private static final int COMP_LEVEL;
  48     static {


  85 
  86     public static List<CompileCodeTestCase> generate(int bci) {
  87         ArrayList<CompileCodeTestCase> result = new ArrayList<>();
  88         for (Class<?> aClass : CLASSES) {
  89             for (Executable m : aClass.getDeclaredConstructors()) {
  90                 result.add(new CompileCodeTestCase(m, bci));
  91             }
  92             Arrays.stream(aClass.getDeclaredMethods())
  93                     .filter(m -> !Modifier.isAbstract(m.getModifiers()))
  94                     .filter(m -> !Modifier.isNative(m.getModifiers()))
  95                     .map(m -> new CompileCodeTestCase(m, bci))
  96                     .forEach(result::add);
  97         }
  98         return result;
  99     }
 100 
 101     public NMethod toNMethod() {
 102         return NMethod.get(executable, isOsr);
 103     }
 104 








 105     @Override
 106     public String toString() {
 107         return "CompileCodeTestCase{" +
 108                 "executable=" + executable +
 109                 ", bci=" + bci +
 110                 '}';
 111     }
 112 
 113     public void deoptimize() {
 114         WB.deoptimizeMethod(executable, isOsr);
 115     }
 116 
 117     public NMethod deoptimizeAndCompile() {
 118         deoptimize();
 119         return compile();
 120     }
 121 
 122     // classes which are used as "input" data in test cases
 123     private static interface Interface {
 124         Interface interfaceMethod();




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 
  25 package compiler.jvmci.compilerToVM;
  26 
  27 import compiler.jvmci.common.CTVMUtilities;
  28 import compiler.testlibrary.CompilerUtils;
  29 import jdk.test.lib.Utils;
  30 import jdk.vm.ci.code.InstalledCode;
  31 import sun.hotspot.WhiteBox;
  32 import sun.hotspot.code.NMethod;
  33 
  34 import java.lang.reflect.Executable;
  35 import java.lang.reflect.Modifier;
  36 import java.util.ArrayList;
  37 import java.util.Arrays;
  38 import java.util.Collections;
  39 import java.util.HashMap;
  40 import java.util.List;
  41 import java.util.Map;
  42 
  43 /**
  44  * A test case for tests which require compiled code.
  45  */
  46 public final class CompileCodeTestCase {
  47     public static final Map<Class<?>, Object> RECEIVERS;
  48     private static final WhiteBox WB = WhiteBox.getWhiteBox();
  49     private static final int COMP_LEVEL;
  50     static {


  87 
  88     public static List<CompileCodeTestCase> generate(int bci) {
  89         ArrayList<CompileCodeTestCase> result = new ArrayList<>();
  90         for (Class<?> aClass : CLASSES) {
  91             for (Executable m : aClass.getDeclaredConstructors()) {
  92                 result.add(new CompileCodeTestCase(m, bci));
  93             }
  94             Arrays.stream(aClass.getDeclaredMethods())
  95                     .filter(m -> !Modifier.isAbstract(m.getModifiers()))
  96                     .filter(m -> !Modifier.isNative(m.getModifiers()))
  97                     .map(m -> new CompileCodeTestCase(m, bci))
  98                     .forEach(result::add);
  99         }
 100         return result;
 101     }
 102 
 103     public NMethod toNMethod() {
 104         return NMethod.get(executable, isOsr);
 105     }
 106 
 107     public InstalledCode toInstalledCode() {
 108         NMethod nmethod = toNMethod();
 109         long address = nmethod == null ? 0L : nmethod.address;
 110         long entryPoint = nmethod == null ? 0L : nmethod.entry_point;
 111         return CTVMUtilities.getInstalledCode(
 112                 executable.getName(), address, entryPoint);
 113     }
 114 
 115     @Override
 116     public String toString() {
 117         return "CompileCodeTestCase{" +
 118                 "executable=" + executable +
 119                 ", bci=" + bci +
 120                 '}';
 121     }
 122 
 123     public void deoptimize() {
 124         WB.deoptimizeMethod(executable, isOsr);
 125     }
 126 
 127     public NMethod deoptimizeAndCompile() {
 128         deoptimize();
 129         return compile();
 130     }
 131 
 132     // classes which are used as "input" data in test cases
 133     private static interface Interface {
 134         Interface interfaceMethod();


< prev index next >