Mercurial > hg > truffle
annotate agent/test/jdi/SASanityChecker.java @ 8044:2c673161698a
8007402: Code cleanup to remove Parfait false positive
Summary: add array access range check
Reviewed-by: kvn
author | drchase |
---|---|
date | Sat, 09 Feb 2013 12:55:09 -0800 |
parents | c18cbe5936b8 |
children |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
2 * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 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 } |