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