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