< prev index next >

src/share/vm/utilities/ostream.hpp

Print this page
rev 9826 : [mq]: log_attribute
   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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


 219 // from multiple thread may be mixed together. Used by fatal
 220 // error handler.
 221 class fdStream : public outputStream {
 222  protected:
 223   int  _fd;
 224   bool _need_close;
 225  public:
 226   fdStream(const char* file_name);
 227   fdStream(int fd = -1) { _fd = fd; _need_close = false; }
 228   ~fdStream();
 229   bool is_open() const { return _fd != -1; }
 230   void set_fd(int fd) { _fd = fd; _need_close = false; }
 231   int fd() const { return _fd; }
 232   virtual void write(const char* c, size_t len);
 233   void flush() {};
 234 };
 235 
 236 class logStream : public outputStream {
 237 private:
 238   stringStream _current_line;
 239   void (*_log_func)(const char* fmt, ...);
 240 public:
 241   void write(const char* s, size_t len);
 242   logStream(void (*log_func)(const char* fmt, ...)) : _log_func(log_func) {}
 243   ~logStream() {
 244     guarantee(_current_line.size() == 0, "Buffer not flushed. Missing call to print_cr()?");
 245   }
 246 };
 247 
 248 void ostream_init();
 249 void ostream_init_log();
 250 void ostream_exit();
 251 void ostream_abort();
 252 
 253 // staticBufferStream uses a user-supplied buffer for all formatting.
 254 // Used for safe formatting during fatal error handling.  Not MT safe.
 255 // Do not share the stream between multiple threads.
 256 class staticBufferStream : public outputStream {
 257  private:
 258   char* _buffer;
 259   size_t _buflen;


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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 #include "utilities/globalDefinitions.hpp"
  31 
  32 class GCId;
  33 DEBUG_ONLY(class ResourceMark;)
  34 
  35 // Output streams for printing
  36 //
  37 // Printing guidelines:
  38 // Where possible, please use tty->print() and tty->print_cr().
  39 // For product mode VM warnings use warning() which internally uses tty.
  40 // In places where tty is not initialized yet or too much overhead,
  41 // we may use jio_printf:
  42 //     jio_fprintf(defaultStream::output_stream(), "Message");
  43 // This allows for redirection via -XX:+DisplayVMOutputToStdout and
  44 // -XX:+DisplayVMOutputToStderr
  45 class outputStream : public ResourceObj {
  46  protected:
  47    int _indentation; // current indentation
  48    int _width;       // width of the page
  49    int _position;    // position on the current line
  50    int _newlines;    // number of '\n' output so far


 220 // from multiple thread may be mixed together. Used by fatal
 221 // error handler.
 222 class fdStream : public outputStream {
 223  protected:
 224   int  _fd;
 225   bool _need_close;
 226  public:
 227   fdStream(const char* file_name);
 228   fdStream(int fd = -1) { _fd = fd; _need_close = false; }
 229   ~fdStream();
 230   bool is_open() const { return _fd != -1; }
 231   void set_fd(int fd) { _fd = fd; _need_close = false; }
 232   int fd() const { return _fd; }
 233   virtual void write(const char* c, size_t len);
 234   void flush() {};
 235 };
 236 
 237 class logStream : public outputStream {
 238 private:
 239   stringStream _current_line;
 240   void (*_log_func)(const char* fmt, ...) ATTRIBUTE_PRINTF(1, 2);
 241 public:
 242   void write(const char* s, size_t len);
 243   logStream(void (*log_func)(const char* fmt, ...)) : _log_func(log_func) {}
 244   ~logStream() {
 245     guarantee(_current_line.size() == 0, "Buffer not flushed. Missing call to print_cr()?");
 246   }
 247 };
 248 
 249 void ostream_init();
 250 void ostream_init_log();
 251 void ostream_exit();
 252 void ostream_abort();
 253 
 254 // staticBufferStream uses a user-supplied buffer for all formatting.
 255 // Used for safe formatting during fatal error handling.  Not MT safe.
 256 // Do not share the stream between multiple threads.
 257 class staticBufferStream : public outputStream {
 258  private:
 259   char* _buffer;
 260   size_t _buflen;


< prev index next >