hotspot/src/share/vm/prims/jvmtiGen.java
author coleenp
Fri, 20 Sep 2013 09:30:02 -0400
changeset 20059 c26474fd5ac0
parent 18025 b7bcf7497f93
child 33773 caf1d935e1c7
permissions -rw-r--r--
8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously Summary: Need to refetch each method from InstanceKlass after all safepoints. Removed leaky PreviousVersionInfo code. Reviewed-by: dcubed, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 5547
diff changeset
     2
 * Copyright (c) 2003, 2013, 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 javax.xml.parsers.DocumentBuilder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
import javax.xml.parsers.DocumentBuilderFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import javax.xml.parsers.FactoryConfigurationError;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import javax.xml.parsers.ParserConfigurationException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import org.xml.sax.SAXException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import org.xml.sax.SAXParseException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import org.w3c.dom.Document;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import org.w3c.dom.DOMException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// For write operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import javax.xml.transform.Transformer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import javax.xml.transform.TransformerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import javax.xml.transform.TransformerFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
import javax.xml.transform.TransformerConfigurationException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
import javax.xml.transform.dom.DOMSource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
import javax.xml.transform.stream.StreamSource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
import javax.xml.transform.stream.StreamResult;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
public class jvmtiGen
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    /**
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
     * Write out usage and exit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
     */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    private static void showUsage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
        System.err.println("usage:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
        System.err.println("  java jvmtiGen " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                           "-IN <input XML file name> " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                           "-XSL <XSL file> " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                           "-OUT <output file name> " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                           "[-PARAM <name> <expression> ...]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        System.exit(0);         // There is no returning from showUsage()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    // Global value so it can be ref'd by the tree-adapter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    static Document document;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    public static void main (String argv [])
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
        String inFileName=null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
        String xslFileName=null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        String outFileName=null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
        java.util.Vector<String> params=new java.util.Vector<String>();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        for (int ii = 0; ii < argv.length; ii++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
            if (argv[ii].equals("-IN")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                inFileName = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
            } else if (argv[ii].equals("-XSL")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
                xslFileName = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
            } else if (argv[ii].equals("-OUT")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                outFileName = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
            } else if (argv[ii].equals("-PARAM")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                if (ii + 2 < argv.length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                    String name = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                    params.addElement(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                    String expression = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                    params.addElement(expression);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                    showUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
                showUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
        if (inFileName==null || xslFileName==null || outFileName==null){
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
            showUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
         * Due to JAXP breakage in some intermediate Tiger builds, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
         * com.sun.org.apache..... parser may throw an exception:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
         *   com.sun.org.apache.xml.internal.utils.WrappedRuntimeException:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
         *     org.apache.xalan.serialize.SerializerToText
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
         *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
         * To work around the problem, this program uses the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
         * org.apache.xalan....  version if it is available.  It is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
         * available in J2SE 1.4.x and early builds of 1.5 (Tiger).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
         * It was removed at the same time the thrown exception issue
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
         * above was fixed, so if the class is not found we can proceed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
         * and use the default parser.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
         */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        final String parserProperty =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
            "javax.xml.transform.TransformerFactory";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        final String workaroundParser =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
            "org.apache.xalan.processor.TransformerFactoryImpl";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
            java.lang.Class cls = java.lang.Class.forName(workaroundParser);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
            /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
             * If we get here, we found the class.  Use it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
             */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
            System.setProperty(parserProperty, workaroundParser);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
            System.out.println("Info: jvmtiGen using " + parserProperty +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
                               " = " + workaroundParser);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        } catch (ClassNotFoundException cnfex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
            /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
             * We didn't find workaroundParser.  Ignore the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
             * exception and proceed with default settings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
             */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        DocumentBuilderFactory factory =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
            DocumentBuilderFactory.newInstance();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        factory.setNamespaceAware(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        factory.setValidating(true);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 5547
diff changeset
   131
        factory.setXIncludeAware(true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
            File datafile   = new File(inFileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
            File stylesheet = new File(xslFileName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
            DocumentBuilder builder = factory.newDocumentBuilder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
            document = builder.parse(datafile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
            // Use a Transformer for output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
            TransformerFactory tFactory =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                TransformerFactory.newInstance();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
            StreamSource stylesource = new StreamSource(stylesheet);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
            Transformer transformer = tFactory.newTransformer(stylesource);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
            for (int ii = 0; ii < params.size(); ii += 2){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
                transformer.setParameter((String) params.elementAt(ii),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
                                         (String) params.elementAt(ii + 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
            DOMSource source = new DOMSource(document);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
            PrintStream ps = new PrintStream( new FileOutputStream(outFileName));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
            StreamResult result = new StreamResult(ps);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
            transformer.transform(source, result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        } catch (TransformerConfigurationException tce) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
           // Error generated by the parser
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
           System.out.println ("\n** Transformer Factory error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
           System.out.println("   " + tce.getMessage() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
           // Use the contained exception, if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
           Throwable x = tce;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
           if (tce.getException() != null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
               x = tce.getException();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
           x.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        } catch (TransformerException te) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
           // Error generated by the parser
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
           System.out.println ("\n** Transformation error");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
           System.out.println("   " + te.getMessage() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
           // Use the contained exception, if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
           Throwable x = te;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
           if (te.getException() != null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
               x = te.getException();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
           x.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
         } catch (SAXException sxe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
           // Error generated by this application
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
           // (or a parser-initialization error)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
           Exception  x = sxe;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
           if (sxe.getException() != null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
               x = sxe.getException();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
           x.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
        } catch (ParserConfigurationException pce) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
            // Parser with specified options can't be built
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
            pce.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        } catch (IOException ioe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
           // I/O error
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
           ioe.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    } // main
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}