hotspot/src/share/vm/prims/jvmtiGen.java
author ysr
Thu, 03 Dec 2009 15:01:57 -0800
changeset 4461 c17c526d36ef
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6906727: UseCompressedOops: some card-marking fixes related to object arrays Summary: Introduced a new write_ref_array(HeapWords* start, size_t count) method that does the requisite MemRegion range calculation so (some of the) clients of the erstwhile write_ref_array(MemRegion mr) do not need to worry. This removed all external uses of array_size(), which was also simplified and made private. Asserts were added to catch other possible issues. Further, less essential, fixes stemming from this investigation are deferred to CR 6904516 (to follow shortly in hs17). Reviewed-by: kvn, coleenp, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// For write operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import javax.xml.transform.Transformer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import javax.xml.transform.TransformerException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
import javax.xml.transform.TransformerFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
import javax.xml.transform.TransformerConfigurationException;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
import javax.xml.transform.dom.DOMSource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
import javax.xml.transform.stream.StreamSource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
import javax.xml.transform.stream.StreamResult;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
public class jvmtiGen
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    /**
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
     * Write out usage and exit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
     */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    private static void showUsage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
        System.err.println("usage:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
        System.err.println("  java jvmtiGen " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                           "-IN <input XML file name> " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                           "-XSL <XSL file> " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                           "-OUT <output file name> " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
                           "[-PARAM <name> <expression> ...]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
        System.exit(0);         // There is no returning from showUsage()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    // Global value so it can be ref'd by the tree-adapter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    static Document document;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    public static void main (String argv [])
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
        String inFileName=null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        String xslFileName=null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
        String outFileName=null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        java.util.Vector<String> params=new java.util.Vector<String>();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        for (int ii = 0; ii < argv.length; ii++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
            if (argv[ii].equals("-IN")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
                inFileName = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
            } else if (argv[ii].equals("-XSL")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                xslFileName = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
            } else if (argv[ii].equals("-OUT")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                outFileName = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
            } else if (argv[ii].equals("-PARAM")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                if (ii + 2 < argv.length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                    String name = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                    params.addElement(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                    String expression = argv[++ii];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                    params.addElement(expression);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                    showUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
                }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                showUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
        if (inFileName==null || xslFileName==null || outFileName==null){
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
            showUsage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
         * Due to JAXP breakage in some intermediate Tiger builds, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
         * com.sun.org.apache..... parser may throw an exception:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
         *   com.sun.org.apache.xml.internal.utils.WrappedRuntimeException:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
         *     org.apache.xalan.serialize.SerializerToText
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
         *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
         * To work around the problem, this program uses the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
         * org.apache.xalan....  version if it is available.  It is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
         * available in J2SE 1.4.x and early builds of 1.5 (Tiger).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
         * It was removed at the same time the thrown exception issue
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
         * above was fixed, so if the class is not found we can proceed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
         * and use the default parser.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
         */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        final String parserProperty =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
            "javax.xml.transform.TransformerFactory";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        final String workaroundParser =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
            "org.apache.xalan.processor.TransformerFactoryImpl";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
            java.lang.Class cls = java.lang.Class.forName(workaroundParser);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
            /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
             * If we get here, we found the class.  Use it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
             */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
            System.setProperty(parserProperty, workaroundParser);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
            System.out.println("Info: jvmtiGen using " + parserProperty +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
                               " = " + workaroundParser);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        } catch (ClassNotFoundException cnfex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
            /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
             * We didn't find workaroundParser.  Ignore the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
             * exception and proceed with default settings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
             */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        DocumentBuilderFactory factory =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
            DocumentBuilderFactory.newInstance();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        factory.setNamespaceAware(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        factory.setValidating(true);
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
}