|
1 /* |
|
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 * |
|
23 */ |
|
24 |
|
25 import sun.jvm.hotspot.tools.*; |
|
26 import sun.jvm.hotspot.runtime.*; |
|
27 import java.io.*; |
|
28 import java.util.*; |
|
29 import java.util.jar.*; |
|
30 |
|
31 /** |
|
32 This is a sanity checking tool for Serviceability Agent. To use this class, |
|
33 refer to sasanity.sh script in the current directory. |
|
34 */ |
|
35 |
|
36 public class SASanityChecker extends Tool { |
|
37 private static final String saJarName; |
|
38 private static final Map c2types; |
|
39 |
|
40 static { |
|
41 saJarName = System.getProperty("SASanityChecker.SAJarName", "sa-jdi.jar"); |
|
42 c2types = new HashMap(); |
|
43 Object value = new Object(); |
|
44 c2types.put("sun.jvm.hotspot.code.ExceptionBlob", value); |
|
45 c2types.put("sun.jvm.hotspot.code.DeoptimizationBlob", value); |
|
46 c2types.put("sun.jvm.hotspot.code.UncommonTrapBlob", value); |
|
47 |
|
48 } |
|
49 |
|
50 public void run() { |
|
51 String classPath = System.getProperty("java.class.path"); |
|
52 StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator); |
|
53 String saJarPath = null; |
|
54 while (st.hasMoreTokens()) { |
|
55 saJarPath = st.nextToken(); |
|
56 if (saJarPath.endsWith(saJarName)) { |
|
57 break; |
|
58 } |
|
59 } |
|
60 |
|
61 if (saJarPath == null) { |
|
62 throw new RuntimeException(saJarName + " is not the CLASSPATH"); |
|
63 } |
|
64 |
|
65 String cpuDot = "." + VM.getVM().getCPU() + "."; |
|
66 String platformDot = "." + VM.getVM().getOS() + "_" + VM.getVM().getCPU() + "."; |
|
67 boolean isClient = VM.getVM().isClientCompiler(); |
|
68 |
|
69 try { |
|
70 FileInputStream fis = new FileInputStream(saJarPath); |
|
71 JarInputStream jis = new JarInputStream(fis); |
|
72 JarEntry je = null; |
|
73 while ( (je = jis.getNextJarEntry()) != null) { |
|
74 String entryName = je.getName(); |
|
75 int dotClassIndex = entryName.indexOf(".class"); |
|
76 if (dotClassIndex == -1) { |
|
77 // skip non-.class stuff |
|
78 continue; |
|
79 } |
|
80 |
|
81 entryName = entryName.substring(0, dotClassIndex).replace('/', '.'); |
|
82 |
|
83 // skip debugger, asm classes, type classes and jdi binding classes |
|
84 if (entryName.startsWith("sun.jvm.hotspot.debugger.") || |
|
85 entryName.startsWith("sun.jvm.hotspot.asm.") || |
|
86 entryName.startsWith("sun.jvm.hotspot.type.") || |
|
87 entryName.startsWith("sun.jvm.hotspot.jdi.") ) { |
|
88 continue; |
|
89 } |
|
90 |
|
91 String runtimePkgPrefix = "sun.jvm.hotspot.runtime."; |
|
92 int runtimeIndex = entryName.indexOf(runtimePkgPrefix); |
|
93 if (runtimeIndex != -1) { |
|
94 // look for further dot. if there, it has to be sub-package. |
|
95 // in runtime sub-packages include only current platform classes. |
|
96 if (entryName.substring(runtimePkgPrefix.length() + 1, entryName.length()).indexOf('.') != -1) { |
|
97 if (entryName.indexOf(cpuDot) == -1 && |
|
98 entryName.indexOf(platformDot) == -1) { |
|
99 continue; |
|
100 } |
|
101 } |
|
102 } |
|
103 |
|
104 if (isClient) { |
|
105 if (c2types.get(entryName) != null) { |
|
106 continue; |
|
107 } |
|
108 } else { |
|
109 if (entryName.equals("sun.jvm.hotspot.c1.Runtime1")) { |
|
110 continue; |
|
111 } |
|
112 } |
|
113 |
|
114 System.out.println("checking " + entryName + " .."); |
|
115 // force init of the class to uncover any vmStructs mismatch |
|
116 Class.forName(entryName); |
|
117 } |
|
118 } catch (Exception exp) { |
|
119 System.out.println(); |
|
120 System.out.println("FAILED"); |
|
121 System.out.println(); |
|
122 throw new RuntimeException(exp.getMessage()); |
|
123 } |
|
124 System.out.println(); |
|
125 System.out.println("PASSED"); |
|
126 System.out.println(); |
|
127 } |
|
128 |
|
129 public static void main(String[] args) { |
|
130 SASanityChecker checker = new SASanityChecker(); |
|
131 checker.start(args); |
|
132 checker.stop(); |
|
133 } |
|
134 } |