Sat, 18 May 2013 20:41:01 -0700
8014262: PrintStringTableStatistics should include more footprint info
Summary: Added info for the string/symbol objects and the hash entries
Reviewed-by: coleenp, rbackman
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_UTILITIES_XMLSTREAM_HPP |
stefank@2314 | 26 | #define SHARE_VM_UTILITIES_XMLSTREAM_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "runtime/handles.hpp" |
stefank@2314 | 29 | #include "utilities/ostream.hpp" |
stefank@2314 | 30 | |
duke@435 | 31 | class xmlStream; |
duke@435 | 32 | class defaultStream; |
duke@435 | 33 | |
duke@435 | 34 | // Sub-stream for writing quoted text, as opposed to markup. |
duke@435 | 35 | // Characters written to this stream are subject to quoting, |
duke@435 | 36 | // as '<' => "<", etc. |
duke@435 | 37 | class xmlTextStream : public outputStream { |
duke@435 | 38 | friend class xmlStream; |
duke@435 | 39 | friend class defaultStream; // tty |
duke@435 | 40 | private: |
duke@435 | 41 | |
duke@435 | 42 | xmlStream* _outer_xmlStream; |
duke@435 | 43 | |
duke@435 | 44 | xmlTextStream() { _outer_xmlStream = NULL; } |
duke@435 | 45 | |
duke@435 | 46 | public: |
duke@435 | 47 | virtual void flush(); // _outer.flush(); |
duke@435 | 48 | virtual void write(const char* str, size_t len); // _outer->write_text() |
duke@435 | 49 | }; |
duke@435 | 50 | |
duke@435 | 51 | |
duke@435 | 52 | // Output stream for writing XML-structured logs. |
duke@435 | 53 | // To write markup, use special calls elem, head/tail, etc. |
duke@435 | 54 | // Use the xmlStream::text() stream to write unmarked text. |
duke@435 | 55 | // Text written that way will be quoted as necessary using '<', etc. |
duke@435 | 56 | // Characters written directly to an xmlStream via print_cr, etc., |
duke@435 | 57 | // are directly written to the encapsulated stream, xmlStream::out(). |
duke@435 | 58 | // This can be used to produce markup directly, character by character. |
duke@435 | 59 | // (Such writes are not checked for markup syntax errors.) |
duke@435 | 60 | |
duke@435 | 61 | class xmlStream : public outputStream { |
duke@435 | 62 | friend class defaultStream; // tty |
duke@435 | 63 | public: |
duke@435 | 64 | enum MarkupState { BODY, // after end_head() call, in text |
duke@435 | 65 | HEAD, // after begin_head() call, in attrs |
duke@435 | 66 | ELEM }; // after begin_elem() call, in attrs |
duke@435 | 67 | |
duke@435 | 68 | protected: |
duke@435 | 69 | outputStream* _out; // file stream by which it goes |
duke@435 | 70 | julong _last_flush; // last position of flush |
duke@435 | 71 | MarkupState _markup_state; // where in the elem/head/tail dance |
duke@435 | 72 | outputStream* _text; // text stream |
duke@435 | 73 | xmlTextStream _text_init; |
duke@435 | 74 | |
duke@435 | 75 | // for subclasses |
duke@435 | 76 | xmlStream() {} |
duke@435 | 77 | void initialize(outputStream* out); |
duke@435 | 78 | |
duke@435 | 79 | // protect this from public use: |
duke@435 | 80 | outputStream* out() { return _out; } |
duke@435 | 81 | |
duke@435 | 82 | // helpers for writing XML elements |
duke@435 | 83 | void va_tag(bool push, const char* format, va_list ap); |
duke@435 | 84 | virtual void see_tag(const char* tag, bool push) NOT_DEBUG({}); |
duke@435 | 85 | virtual void pop_tag(const char* tag) NOT_DEBUG({}); |
duke@435 | 86 | |
duke@435 | 87 | #ifdef ASSERT |
duke@435 | 88 | // in debug mode, we verify matching of opening and closing tags |
duke@435 | 89 | int _element_depth; // number of unfinished elements |
duke@435 | 90 | char* _element_close_stack_high; // upper limit of down-growing stack |
duke@435 | 91 | char* _element_close_stack_low; // upper limit of down-growing stack |
duke@435 | 92 | char* _element_close_stack_ptr; // pointer of down-growing stack |
duke@435 | 93 | #endif |
duke@435 | 94 | |
duke@435 | 95 | public: |
duke@435 | 96 | // creation |
duke@435 | 97 | xmlStream(outputStream* out) { initialize(out); } |
duke@435 | 98 | DEBUG_ONLY(virtual ~xmlStream();) |
duke@435 | 99 | |
duke@435 | 100 | bool is_open() { return _out != NULL; } |
duke@435 | 101 | |
duke@435 | 102 | // text output |
duke@435 | 103 | bool inside_attrs() { return _markup_state != BODY; } |
duke@435 | 104 | |
duke@435 | 105 | // flushing |
duke@435 | 106 | virtual void flush(); // flushes out, sets _last_flush = count() |
duke@435 | 107 | virtual void write(const char* s, size_t len); |
duke@435 | 108 | void write_text(const char* s, size_t len); // used by xmlTextStream |
duke@435 | 109 | int unflushed_count() { return (int)(out()->count() - _last_flush); } |
duke@435 | 110 | |
duke@435 | 111 | // writing complete XML elements |
duke@435 | 112 | void elem(const char* format, ...); |
duke@435 | 113 | void begin_elem(const char* format, ...); |
duke@435 | 114 | void end_elem(const char* format, ...); |
duke@435 | 115 | void end_elem(); |
duke@435 | 116 | void head(const char* format, ...); |
duke@435 | 117 | void begin_head(const char* format, ...); |
duke@435 | 118 | void end_head(const char* format, ...); |
duke@435 | 119 | void end_head(); |
duke@435 | 120 | void done(const char* format, ...); // xxx_done event, plus tail |
duke@435 | 121 | void done_raw(const char * kind); |
duke@435 | 122 | void tail(const char* kind); |
duke@435 | 123 | |
duke@435 | 124 | // va_list versions |
duke@435 | 125 | void va_elem(const char* format, va_list ap); |
duke@435 | 126 | void va_begin_elem(const char* format, va_list ap); |
duke@435 | 127 | void va_head(const char* format, va_list ap); |
duke@435 | 128 | void va_begin_head(const char* format, va_list ap); |
duke@435 | 129 | void va_done(const char* format, va_list ap); |
duke@435 | 130 | |
duke@435 | 131 | // write text (with quoting of special XML characters <>&'" etc.) |
duke@435 | 132 | outputStream* text() { return _text; } |
duke@435 | 133 | void text(const char* format, ...); |
duke@435 | 134 | void va_text(const char* format, va_list ap) { |
duke@435 | 135 | text()->vprint(format, ap); |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | // commonly used XML attributes |
duke@435 | 139 | void stamp(); // stamp='1.234' |
duke@435 | 140 | void method(methodHandle m); // method='k n s' ... |
duke@435 | 141 | void klass(KlassHandle k); // klass='name' |
coleenp@2497 | 142 | void name(const Symbol* s); // name='name' |
coleenp@4037 | 143 | void object(const char* attr, Metadata* val); |
duke@435 | 144 | void object(const char* attr, Handle val); |
duke@435 | 145 | |
duke@435 | 146 | // print the text alone (sans ''): |
duke@435 | 147 | void method_text(methodHandle m); |
duke@435 | 148 | void klass_text(KlassHandle k); // klass='name' |
coleenp@2497 | 149 | void name_text(const Symbol* s); // name='name' |
coleenp@4037 | 150 | void object_text(Metadata* x); |
duke@435 | 151 | void object_text(Handle x); |
duke@435 | 152 | |
duke@435 | 153 | /* Example uses: |
duke@435 | 154 | |
duke@435 | 155 | // Empty element, simple case. |
duke@435 | 156 | elem("X Y='Z'"); <X Y='Z'/> \n |
duke@435 | 157 | |
duke@435 | 158 | // Empty element, general case. |
duke@435 | 159 | begin_elem("X Y='Z'"); <X Y='Z' |
duke@435 | 160 | ...attrs... ...attrs... |
duke@435 | 161 | end_elem(); /> |
duke@435 | 162 | |
duke@435 | 163 | // Compound element, simple case. |
duke@435 | 164 | head("X Y='Z'"); <X Y='Z'> \n |
duke@435 | 165 | ...body... ...body... |
duke@435 | 166 | tail("X"); </X> \n |
duke@435 | 167 | |
duke@435 | 168 | // Compound element, general case. |
duke@435 | 169 | begin_head("X Y='Z'"); <X Y='Z' |
duke@435 | 170 | ...attrs... ...attrs... |
duke@435 | 171 | end_head(); > \n |
duke@435 | 172 | ...body... ...body... |
duke@435 | 173 | tail("X"); </X> \n |
duke@435 | 174 | |
duke@435 | 175 | // Printf-style formatting: |
duke@435 | 176 | elem("X Y='%s'", "Z"); <X Y='Z'/> \n |
duke@435 | 177 | |
duke@435 | 178 | */ |
duke@435 | 179 | |
duke@435 | 180 | }; |
duke@435 | 181 | |
duke@435 | 182 | // Standard log file, null if no logging is happening. |
duke@435 | 183 | extern xmlStream* xtty; |
duke@435 | 184 | |
duke@435 | 185 | // Note: If ::xtty != NULL, ::tty == ::xtty->text(). |
stefank@2314 | 186 | |
stefank@2314 | 187 | #endif // SHARE_VM_UTILITIES_XMLSTREAM_HPP |