< prev index next >

test/jtreg-ext/requires/VMProps.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   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 package requires;
  24 
  25 import java.io.BufferedInputStream;

  26 import java.io.FileInputStream;
  27 import java.io.IOException;
  28 import java.io.InputStream;

  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.nio.file.Paths;
  32 import java.nio.file.StandardOpenOption;
  33 import java.util.ArrayList;
  34 import java.util.HashMap;
  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.Properties;
  38 import java.util.concurrent.Callable;
  39 import java.util.concurrent.TimeUnit;
  40 import java.util.function.Supplier;
  41 import java.util.regex.Matcher;
  42 import java.util.regex.Pattern;
  43 
  44 import sun.hotspot.code.Compiler;
  45 import sun.hotspot.cpuinfo.CPUInfo;
  46 import sun.hotspot.gc.GC;
  47 import sun.hotspot.WhiteBox;
  48 import jdk.test.lib.Platform;


  98         // vm.hasSAandCanAttach is "true" if the VM contains the serviceability agent
  99         // and jhsdb and it can attach to the VM.
 100         map.put("vm.hasSAandCanAttach", this::vmHasSAandCanAttach);
 101         // vm.hasJFR is "true" if JFR is included in the build of the VM and
 102         // so tests can be executed.
 103         map.put("vm.hasJFR", this::vmHasJFR);
 104         map.put("vm.cpu.features", this::cpuFeatures);
 105         map.put("vm.rtm.cpu", this::vmRTMCPU);
 106         map.put("vm.rtm.compiler", this::vmRTMCompiler);
 107         map.put("vm.aot", this::vmAOT);
 108         map.put("vm.aot.enabled", this::vmAotEnabled);
 109         // vm.cds is true if the VM is compiled with cds support.
 110         map.put("vm.cds", this::vmCDS);
 111         map.put("vm.cds.custom.loaders", this::vmCDSForCustomLoaders);
 112         map.put("vm.cds.archived.java.heap", this::vmCDSForArchivedJavaHeap);
 113         // vm.graal.enabled is true if Graal is used as JIT
 114         map.put("vm.graal.enabled", this::isGraalEnabled);
 115         map.put("vm.compiler1.enabled", this::isCompiler1Enabled);
 116         map.put("vm.compiler2.enabled", this::isCompiler2Enabled);
 117         map.put("docker.support", this::dockerSupport);

 118         map.put("release.implementor", this::implementor);
 119         map.put("test.vm.gc.nvdimm", this::isNvdimmTestEnabled);
 120         vmGC(map); // vm.gc.X = true/false
 121         vmOptFinalFlags(map);
 122 
 123         dump(map.map);
 124         return map.map;
 125     }
 126 
 127     /**
 128      * Print a stack trace before returning error state;
 129      * Used by the various helper functions which parse information from
 130      * VM properties in the case where they don't find an expected property
 131      * or a property doesn't conform to an expected format.
 132      *
 133      * @return {@link #ERROR_STATE}
 134      */
 135     private String errorWithMessage(String message) {
 136         new Exception(message).printStackTrace();
 137         return ERROR_STATE + message;


 443            }
 444         }
 445 
 446         if (isSupported) {
 447            try {
 448               isSupported = checkDockerSupport();
 449            } catch (Exception e) {
 450               isSupported = false;
 451            }
 452          }
 453 
 454         return "" + isSupported;
 455     }
 456 
 457     private boolean checkDockerSupport() throws IOException, InterruptedException {
 458         ProcessBuilder pb = new ProcessBuilder("docker", "ps");
 459         Process p = pb.start();
 460         p.waitFor(10, TimeUnit.SECONDS);
 461 
 462         return (p.exitValue() == 0);




















 463     }
 464 
 465     private String implementor() {
 466         try (InputStream in = new BufferedInputStream(new FileInputStream(
 467                 System.getProperty("java.home") + "/release"))) {
 468             Properties properties = new Properties();
 469             properties.load(in);
 470             String implementorProperty = properties.getProperty("IMPLEMENTOR");
 471             if (implementorProperty != null) {
 472                 return implementorProperty.replace("\"", "");
 473             }
 474             return errorWithMessage("Can't get 'IMPLEMENTOR' property from 'release' file");
 475         } catch (IOException e) {
 476             e.printStackTrace();
 477             return errorWithMessage("Failed to read 'release' file " + e);
 478         }
 479     }
 480 
 481     private String isNvdimmTestEnabled() {
 482         String isEnabled = System.getenv("TEST_VM_GC_NVDIMM");




   6  * under the terms of the GNU General Public License version 2 only, as
   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 package requires;
  24 
  25 import java.io.BufferedInputStream;
  26 import java.io.BufferedReader;
  27 import java.io.FileInputStream;
  28 import java.io.IOException;
  29 import java.io.InputStream;
  30 import java.io.InputStreamReader;
  31 import java.nio.file.Files;
  32 import java.nio.file.Path;
  33 import java.nio.file.Paths;
  34 import java.nio.file.StandardOpenOption;
  35 import java.util.ArrayList;
  36 import java.util.HashMap;
  37 import java.util.List;
  38 import java.util.Map;
  39 import java.util.Properties;
  40 import java.util.concurrent.Callable;
  41 import java.util.concurrent.TimeUnit;
  42 import java.util.function.Supplier;
  43 import java.util.regex.Matcher;
  44 import java.util.regex.Pattern;
  45 
  46 import sun.hotspot.code.Compiler;
  47 import sun.hotspot.cpuinfo.CPUInfo;
  48 import sun.hotspot.gc.GC;
  49 import sun.hotspot.WhiteBox;
  50 import jdk.test.lib.Platform;


 100         // vm.hasSAandCanAttach is "true" if the VM contains the serviceability agent
 101         // and jhsdb and it can attach to the VM.
 102         map.put("vm.hasSAandCanAttach", this::vmHasSAandCanAttach);
 103         // vm.hasJFR is "true" if JFR is included in the build of the VM and
 104         // so tests can be executed.
 105         map.put("vm.hasJFR", this::vmHasJFR);
 106         map.put("vm.cpu.features", this::cpuFeatures);
 107         map.put("vm.rtm.cpu", this::vmRTMCPU);
 108         map.put("vm.rtm.compiler", this::vmRTMCompiler);
 109         map.put("vm.aot", this::vmAOT);
 110         map.put("vm.aot.enabled", this::vmAotEnabled);
 111         // vm.cds is true if the VM is compiled with cds support.
 112         map.put("vm.cds", this::vmCDS);
 113         map.put("vm.cds.custom.loaders", this::vmCDSForCustomLoaders);
 114         map.put("vm.cds.archived.java.heap", this::vmCDSForArchivedJavaHeap);
 115         // vm.graal.enabled is true if Graal is used as JIT
 116         map.put("vm.graal.enabled", this::isGraalEnabled);
 117         map.put("vm.compiler1.enabled", this::isCompiler1Enabled);
 118         map.put("vm.compiler2.enabled", this::isCompiler2Enabled);
 119         map.put("docker.support", this::dockerSupport);
 120         map.put("vm.musl", this::isMusl);
 121         map.put("release.implementor", this::implementor);
 122         map.put("test.vm.gc.nvdimm", this::isNvdimmTestEnabled);
 123         vmGC(map); // vm.gc.X = true/false
 124         vmOptFinalFlags(map);
 125 
 126         dump(map.map);
 127         return map.map;
 128     }
 129 
 130     /**
 131      * Print a stack trace before returning error state;
 132      * Used by the various helper functions which parse information from
 133      * VM properties in the case where they don't find an expected property
 134      * or a property doesn't conform to an expected format.
 135      *
 136      * @return {@link #ERROR_STATE}
 137      */
 138     private String errorWithMessage(String message) {
 139         new Exception(message).printStackTrace();
 140         return ERROR_STATE + message;


 446            }
 447         }
 448 
 449         if (isSupported) {
 450            try {
 451               isSupported = checkDockerSupport();
 452            } catch (Exception e) {
 453               isSupported = false;
 454            }
 455          }
 456 
 457         return "" + isSupported;
 458     }
 459 
 460     private boolean checkDockerSupport() throws IOException, InterruptedException {
 461         ProcessBuilder pb = new ProcessBuilder("docker", "ps");
 462         Process p = pb.start();
 463         p.waitFor(10, TimeUnit.SECONDS);
 464 
 465         return (p.exitValue() == 0);
 466     }
 467 
 468     /**
 469      * Check if we run with musl libc.
 470      *
 471      * @return true if we run with musl libc.
 472      */
 473     protected String isMusl() {
 474         try {
 475             ProcessBuilder pb = new ProcessBuilder("ldd", "--version");
 476             pb.redirectErrorStream(true);
 477             final Process p = pb.start();
 478             BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
 479             String line = br.readLine();
 480             if (line != null && line.contains("musl")) {
 481                 return "true";
 482             }
 483         } catch (Exception e) {
 484         }
 485         return "false";
 486     }
 487 
 488     private String implementor() {
 489         try (InputStream in = new BufferedInputStream(new FileInputStream(
 490                 System.getProperty("java.home") + "/release"))) {
 491             Properties properties = new Properties();
 492             properties.load(in);
 493             String implementorProperty = properties.getProperty("IMPLEMENTOR");
 494             if (implementorProperty != null) {
 495                 return implementorProperty.replace("\"", "");
 496             }
 497             return errorWithMessage("Can't get 'IMPLEMENTOR' property from 'release' file");
 498         } catch (IOException e) {
 499             e.printStackTrace();
 500             return errorWithMessage("Failed to read 'release' file " + e);
 501         }
 502     }
 503 
 504     private String isNvdimmTestEnabled() {
 505         String isEnabled = System.getenv("TEST_VM_GC_NVDIMM");


< prev index next >