0N/A/*
1472N/A * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
0N/Aimport sun.jvm.hotspot.tools.*;
0N/Aimport sun.jvm.hotspot.runtime.*;
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/Aimport java.util.jar.*;
0N/A
0N/A/**
0N/AThis is a sanity checking tool for Serviceability Agent. To use this class,
0N/Arefer to sasanity.sh script in the current directory.
0N/A*/
0N/A
0N/Apublic class SASanityChecker extends Tool {
0N/A private static final String saJarName;
0N/A private static final Map c2types;
0N/A
0N/A static {
0N/A saJarName = System.getProperty("SASanityChecker.SAJarName", "sa-jdi.jar");
0N/A c2types = new HashMap();
0N/A Object value = new Object();
0N/A c2types.put("sun.jvm.hotspot.code.ExceptionBlob", value);
0N/A c2types.put("sun.jvm.hotspot.code.DeoptimizationBlob", value);
0N/A c2types.put("sun.jvm.hotspot.code.UncommonTrapBlob", value);
0N/A
0N/A }
0N/A
0N/A public void run() {
0N/A String classPath = System.getProperty("java.class.path");
0N/A StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator);
0N/A String saJarPath = null;
0N/A while (st.hasMoreTokens()) {
0N/A saJarPath = st.nextToken();
0N/A if (saJarPath.endsWith(saJarName)) {
0N/A break;
0N/A }
0N/A }
0N/A
0N/A if (saJarPath == null) {
0N/A throw new RuntimeException(saJarName + " is not the CLASSPATH");
0N/A }
0N/A
0N/A String cpuDot = "." + VM.getVM().getCPU() + ".";
0N/A String platformDot = "." + VM.getVM().getOS() + "_" + VM.getVM().getCPU() + ".";
0N/A boolean isClient = VM.getVM().isClientCompiler();
0N/A
0N/A try {
0N/A FileInputStream fis = new FileInputStream(saJarPath);
0N/A JarInputStream jis = new JarInputStream(fis);
0N/A JarEntry je = null;
0N/A while ( (je = jis.getNextJarEntry()) != null) {
0N/A String entryName = je.getName();
0N/A int dotClassIndex = entryName.indexOf(".class");
0N/A if (dotClassIndex == -1) {
0N/A // skip non-.class stuff
0N/A continue;
0N/A }
0N/A
0N/A entryName = entryName.substring(0, dotClassIndex).replace('/', '.');
0N/A
0N/A // skip debugger, asm classes, type classes and jdi binding classes
0N/A if (entryName.startsWith("sun.jvm.hotspot.debugger.") ||
0N/A entryName.startsWith("sun.jvm.hotspot.asm.") ||
0N/A entryName.startsWith("sun.jvm.hotspot.type.") ||
0N/A entryName.startsWith("sun.jvm.hotspot.jdi.") ) {
0N/A continue;
0N/A }
0N/A
0N/A String runtimePkgPrefix = "sun.jvm.hotspot.runtime.";
0N/A int runtimeIndex = entryName.indexOf(runtimePkgPrefix);
0N/A if (runtimeIndex != -1) {
0N/A // look for further dot. if there, it has to be sub-package.
0N/A // in runtime sub-packages include only current platform classes.
0N/A if (entryName.substring(runtimePkgPrefix.length() + 1, entryName.length()).indexOf('.') != -1) {
0N/A if (entryName.indexOf(cpuDot) == -1 &&
0N/A entryName.indexOf(platformDot) == -1) {
0N/A continue;
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (isClient) {
0N/A if (c2types.get(entryName) != null) {
0N/A continue;
0N/A }
0N/A } else {
0N/A if (entryName.equals("sun.jvm.hotspot.c1.Runtime1")) {
0N/A continue;
0N/A }
0N/A }
0N/A
0N/A System.out.println("checking " + entryName + " ..");
0N/A // force init of the class to uncover any vmStructs mismatch
0N/A Class.forName(entryName);
0N/A }
0N/A } catch (Exception exp) {
0N/A System.out.println();
0N/A System.out.println("FAILED");
0N/A System.out.println();
0N/A throw new RuntimeException(exp.getMessage());
0N/A }
0N/A System.out.println();
0N/A System.out.println("PASSED");
0N/A System.out.println();
0N/A }
0N/A
0N/A public static void main(String[] args) {
0N/A SASanityChecker checker = new SASanityChecker();
0N/A checker.start(args);
0N/A checker.stop();
0N/A }
0N/A}