agent/test/jdi/SASanityChecker.java

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 1907
c18cbe5936b8
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

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

mercurial