< prev index next >

src/share/vm/utilities/ostream.hpp

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_OSTREAM_HPP
  26 #define SHARE_VM_UTILITIES_OSTREAM_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/timer.hpp"
  30 
  31 class GCId;
  32 DEBUG_ONLY(class ResourceMark;)
  33 
  34 // Output streams for printing
  35 //
  36 // Printing guidelines:
  37 // Where possible, please use tty->print() and tty->print_cr().
  38 // For product mode VM warnings use warning() which internally uses tty.
  39 // In places where tty is not initialized yet or too much overhead,
  40 // we may use jio_printf:
  41 //     jio_fprintf(defaultStream::output_stream(), "Message");
  42 // This allows for redirection via -XX:+DisplayVMOutputToStdout and
  43 // -XX:+DisplayVMOutputToStderr
  44 class outputStream : public ResourceObj {
  45  protected:
  46    int _indentation; // current indentation
  47    int _width;       // width of the page
  48    int _position;    // position on the current line
  49    int _newlines;    // number of '\n' output so far
  50    julong _precount; // number of chars output, less _position
  51    TimeStamp _stamp; // for time stamps


  91    void print_raw_cr(const char* str, int len){ write(str,         len); cr(); }
  92    void print_data(void* data, size_t len, bool with_ascii);
  93    void put(char ch);
  94    void sp(int count = 1);
  95    void cr();
  96    void bol() { if (_position > 0)  cr(); }
  97 
  98    // Time stamp
  99    TimeStamp& time_stamp() { return _stamp; }
 100    void stamp();
 101    void stamp(bool guard, const char* prefix, const char* suffix);
 102    void stamp(bool guard) {
 103      stamp(guard, "", ": ");
 104    }
 105    // Date stamp
 106    void date_stamp(bool guard, const char* prefix, const char* suffix);
 107    // A simplified call that includes a suffix of ": "
 108    void date_stamp(bool guard) {
 109      date_stamp(guard, "", ": ");
 110    }
 111    void gclog_stamp(const GCId& gc_id);
 112 
 113    // portable printing of 64 bit integers
 114    void print_jlong(jlong value);
 115    void print_julong(julong value);
 116 
 117    // flushing
 118    virtual void flush() {}
 119    virtual void write(const char* str, size_t len) = 0;
 120    virtual void rotate_log(bool force, outputStream* out = NULL) {} // GC log rotation
 121    virtual ~outputStream() {}   // close properly on deletion
 122 
 123    void dec_cr() { dec(); cr(); }
 124    void inc_cr() { inc(); cr(); }
 125 };
 126 
 127 // standard output
 128 // ANSI C++ name collision
 129 extern outputStream* tty;           // tty output
 130 extern outputStream* gclog_or_tty;  // stream for gc log if -Xloggc:<f>, or tty
 131 




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_OSTREAM_HPP
  26 #define SHARE_VM_UTILITIES_OSTREAM_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/timer.hpp"
  30 

  31 DEBUG_ONLY(class ResourceMark;)
  32 
  33 // Output streams for printing
  34 //
  35 // Printing guidelines:
  36 // Where possible, please use tty->print() and tty->print_cr().
  37 // For product mode VM warnings use warning() which internally uses tty.
  38 // In places where tty is not initialized yet or too much overhead,
  39 // we may use jio_printf:
  40 //     jio_fprintf(defaultStream::output_stream(), "Message");
  41 // This allows for redirection via -XX:+DisplayVMOutputToStdout and
  42 // -XX:+DisplayVMOutputToStderr
  43 class outputStream : public ResourceObj {
  44  protected:
  45    int _indentation; // current indentation
  46    int _width;       // width of the page
  47    int _position;    // position on the current line
  48    int _newlines;    // number of '\n' output so far
  49    julong _precount; // number of chars output, less _position
  50    TimeStamp _stamp; // for time stamps


  90    void print_raw_cr(const char* str, int len){ write(str,         len); cr(); }
  91    void print_data(void* data, size_t len, bool with_ascii);
  92    void put(char ch);
  93    void sp(int count = 1);
  94    void cr();
  95    void bol() { if (_position > 0)  cr(); }
  96 
  97    // Time stamp
  98    TimeStamp& time_stamp() { return _stamp; }
  99    void stamp();
 100    void stamp(bool guard, const char* prefix, const char* suffix);
 101    void stamp(bool guard) {
 102      stamp(guard, "", ": ");
 103    }
 104    // Date stamp
 105    void date_stamp(bool guard, const char* prefix, const char* suffix);
 106    // A simplified call that includes a suffix of ": "
 107    void date_stamp(bool guard) {
 108      date_stamp(guard, "", ": ");
 109    }
 110    void gclog_stamp();
 111 
 112    // portable printing of 64 bit integers
 113    void print_jlong(jlong value);
 114    void print_julong(julong value);
 115 
 116    // flushing
 117    virtual void flush() {}
 118    virtual void write(const char* str, size_t len) = 0;
 119    virtual void rotate_log(bool force, outputStream* out = NULL) {} // GC log rotation
 120    virtual ~outputStream() {}   // close properly on deletion
 121 
 122    void dec_cr() { dec(); cr(); }
 123    void inc_cr() { inc(); cr(); }
 124 };
 125 
 126 // standard output
 127 // ANSI C++ name collision
 128 extern outputStream* tty;           // tty output
 129 extern outputStream* gclog_or_tty;  // stream for gc log if -Xloggc:<f>, or tty
 130 


< prev index next >