Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/test/jdi/SASanityChecker.java
38764 views
/*1* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import sun.jvm.hotspot.tools.*;25import sun.jvm.hotspot.runtime.*;26import java.io.*;27import java.util.*;28import java.util.jar.*;2930/**31This is a sanity checking tool for Serviceability Agent. To use this class,32refer to sasanity.sh script in the current directory.33*/3435public class SASanityChecker extends Tool {36private static final String saJarName;37private static final Map c2types;3839static {40saJarName = System.getProperty("SASanityChecker.SAJarName", "sa-jdi.jar");41c2types = new HashMap();42Object value = new Object();43c2types.put("sun.jvm.hotspot.code.ExceptionBlob", value);44c2types.put("sun.jvm.hotspot.code.DeoptimizationBlob", value);45c2types.put("sun.jvm.hotspot.code.UncommonTrapBlob", value);4647}4849public void run() {50String classPath = System.getProperty("java.class.path");51StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator);52String saJarPath = null;53while (st.hasMoreTokens()) {54saJarPath = st.nextToken();55if (saJarPath.endsWith(saJarName)) {56break;57}58}5960if (saJarPath == null) {61throw new RuntimeException(saJarName + " is not the CLASSPATH");62}6364String cpuDot = "." + VM.getVM().getCPU() + ".";65String platformDot = "." + VM.getVM().getOS() + "_" + VM.getVM().getCPU() + ".";66boolean isClient = VM.getVM().isClientCompiler();6768try {69FileInputStream fis = new FileInputStream(saJarPath);70JarInputStream jis = new JarInputStream(fis);71JarEntry je = null;72while ( (je = jis.getNextJarEntry()) != null) {73String entryName = je.getName();74int dotClassIndex = entryName.indexOf(".class");75if (dotClassIndex == -1) {76// skip non-.class stuff77continue;78}7980entryName = entryName.substring(0, dotClassIndex).replace('/', '.');8182// skip debugger, asm classes, type classes and jdi binding classes83if (entryName.startsWith("sun.jvm.hotspot.debugger.") ||84entryName.startsWith("sun.jvm.hotspot.asm.") ||85entryName.startsWith("sun.jvm.hotspot.type.") ||86entryName.startsWith("sun.jvm.hotspot.jdi.") ) {87continue;88}8990String runtimePkgPrefix = "sun.jvm.hotspot.runtime.";91int runtimeIndex = entryName.indexOf(runtimePkgPrefix);92if (runtimeIndex != -1) {93// look for further dot. if there, it has to be sub-package.94// in runtime sub-packages include only current platform classes.95if (entryName.substring(runtimePkgPrefix.length() + 1, entryName.length()).indexOf('.') != -1) {96if (entryName.indexOf(cpuDot) == -1 &&97entryName.indexOf(platformDot) == -1) {98continue;99}100}101}102103if (isClient) {104if (c2types.get(entryName) != null) {105continue;106}107} else {108if (entryName.equals("sun.jvm.hotspot.c1.Runtime1")) {109continue;110}111}112113System.out.println("checking " + entryName + " ..");114// force init of the class to uncover any vmStructs mismatch115Class.forName(entryName);116}117} catch (Exception exp) {118System.out.println();119System.out.println("FAILED");120System.out.println();121throw new RuntimeException(exp.getMessage());122}123System.out.println();124System.out.println("PASSED");125System.out.println();126}127128public static void main(String[] args) {129SASanityChecker checker = new SASanityChecker();130checker.start(args);131checker.stop();132}133}134135136