hotspot/src/share/vm/utilities/xmlstream.hpp
author kvn
Thu, 06 Mar 2008 10:30:17 -0800
changeset 211 e2b60448c234
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6667610: (Escape Analysis) retry compilation without EA if it fails Summary: During split unique types EA could exceed nodes limit and fail the method compilation. Reviewed-by: rasbold
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 2002-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
class xmlStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
class defaultStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Sub-stream for writing quoted text, as opposed to markup.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Characters written to this stream are subject to quoting,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// as '<' => "&lt;", etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
class xmlTextStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  friend class xmlStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  friend class defaultStream; // tty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  xmlStream* _outer_xmlStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  xmlTextStream() { _outer_xmlStream = NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
   virtual void flush(); // _outer.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
   virtual void write(const char* str, size_t len); // _outer->write_text()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Output stream for writing XML-structured logs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// To write markup, use special calls elem, head/tail, etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Use the xmlStream::text() stream to write unmarked text.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// Text written that way will be quoted as necessary using '&lt;', etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// Characters written directly to an xmlStream via print_cr, etc.,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// are directly written to the encapsulated stream, xmlStream::out().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// This can be used to produce markup directly, character by character.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// (Such writes are not checked for markup syntax errors.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
class xmlStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  friend class defaultStream; // tty
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  enum MarkupState { BODY,       // after end_head() call, in text
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                     HEAD,       // after begin_head() call, in attrs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
                     ELEM };     // after begin_elem() call, in attrs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  outputStream* _out;            // file stream by which it goes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  julong        _last_flush;     // last position of flush
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  MarkupState   _markup_state;   // where in the elem/head/tail dance
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  outputStream* _text;           // text stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  xmlTextStream _text_init;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // for subclasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  xmlStream() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  void initialize(outputStream* out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // protect this from public use:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  outputStream* out()                            { return _out; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // helpers for writing XML elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  void          va_tag(bool push, const char* format, va_list ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  virtual void see_tag(const char* tag, bool push) NOT_DEBUG({});
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  virtual void pop_tag(const char* tag) NOT_DEBUG({});
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // in debug mode, we verify matching of opening and closing tags
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  int   _element_depth;              // number of unfinished elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  char* _element_close_stack_high;   // upper limit of down-growing stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  char* _element_close_stack_low;    // upper limit of down-growing stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  char* _element_close_stack_ptr;    // pointer of down-growing stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  xmlStream(outputStream* out) { initialize(out); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  DEBUG_ONLY(virtual ~xmlStream();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  bool is_open() { return _out != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // text output
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  bool inside_attrs() { return _markup_state != BODY; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // flushing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  virtual void flush();  // flushes out, sets _last_flush = count()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  virtual void write(const char* s, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void    write_text(const char* s, size_t len);  // used by xmlTextStream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  int unflushed_count() { return (int)(out()->count() - _last_flush); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // writing complete XML elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  void          elem(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  void    begin_elem(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  void      end_elem(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  void      end_elem();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  void          head(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  void    begin_head(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  void      end_head(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  void      end_head();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  void          done(const char* format, ...);  // xxx_done event, plus tail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  void          done_raw(const char * kind);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  void          tail(const char* kind);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // va_list versions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  void       va_elem(const char* format, va_list ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  void va_begin_elem(const char* format, va_list ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void       va_head(const char* format, va_list ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void va_begin_head(const char* format, va_list ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  void       va_done(const char* format, va_list ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // write text (with quoting of special XML characters <>&'" etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  outputStream* text() { return _text; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  void          text(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void       va_text(const char* format, va_list ap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    text()->vprint(format, ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // commonly used XML attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void          stamp();                 // stamp='1.234'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  void          method(methodHandle m);  // method='k n s' ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  void          klass(KlassHandle k);    // klass='name'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  void          name(symbolHandle s);    // name='name'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  void          object(const char* attr, Handle val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // print the text alone (sans ''):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void          method_text(methodHandle m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  void          klass_text(KlassHandle k);    // klass='name'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  void          name_text(symbolHandle s);    // name='name'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  void          object_text(Handle x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  /*  Example uses:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // Empty element, simple case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      elem("X Y='Z'");          <X Y='Z'/> \n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      // Empty element, general case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      begin_elem("X Y='Z'");    <X Y='Z'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      ...attrs...               ...attrs...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      end_elem();               />
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      // Compound element, simple case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      head("X Y='Z'");          <X Y='Z'> \n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      ...body...                ...body...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      tail("X");                </X> \n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      // Compound element, general case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      begin_head("X Y='Z'");    <X Y='Z'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      ...attrs...               ...attrs...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      end_head();               > \n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      ...body...                ...body...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      tail("X");                </X> \n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      // Printf-style formatting:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      elem("X Y='%s'", "Z");    <X Y='Z'/> \n
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
   */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// Standard log file, null if no logging is happening.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
extern xmlStream* xtty;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// Note:  If ::xtty != NULL, ::tty == ::xtty->text().