hotspot/src/share/vm/utilities/ostream.hpp
author trims
Tue, 05 Apr 2011 14:12:31 -0700
changeset 8921 14bfe81f2a9d
parent 8333 11a7f6fc6419
child 9990 c8683968c01b
permissions -rw-r--r--
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8333
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1388
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1388
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1388
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_UTILITIES_OSTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_UTILITIES_OSTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Output streams for printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Printing guidelines:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Where possible, please use tty->print() and tty->print_cr().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// For product mode VM warnings use warning() which internally uses tty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// In places where tty is not initialized yet or too much overhead,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// we may use jio_printf:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//     jio_fprintf(defaultStream::output_stream(), "Message");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// This allows for redirection via -XX:+DisplayVMOutputToStdout and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// -XX:+DisplayVMOutputToStderr
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class outputStream : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
   int _indentation; // current indentation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
   int _width;       // width of the page
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
   int _position;    // position on the current line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
   int _newlines;    // number of '\n' output so far
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
   julong _precount; // number of chars output, less _position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
   TimeStamp _stamp; // for time stamps
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
   void update_position(const char* s, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
   static const char* do_vsnprintf(char* buffer, size_t buflen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                                   const char* format, va_list ap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                                   bool add_cr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                                   size_t& result_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
   // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
   outputStream(int width = 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
   outputStream(int width, bool has_time_stamps);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
   // indentation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
   void indent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
   void inc() { _indentation++; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
   void dec() { _indentation--; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
   int  indentation() const    { return _indentation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
   void set_indentation(int i) { _indentation = i;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
   void fill_to(int col);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 1
diff changeset
    68
   void move_to(int col, int slop = 6, int min_space = 2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
   // sizing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
   int width()    const { return _width;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
   int position() const { return _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
   int newlines() const { return _newlines; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
   julong count() const { return _precount + _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
   void set_count(julong count) { _precount = count - _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
   void set_position(int pos)   { _position = pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
   // printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
   void print(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
   void print_cr(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
   void vprint(const char *format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
   void vprint_cr(const char* format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
   void print_raw(const char* str)            { write(str, strlen(str)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
   void print_raw(const char* str, int len)   { write(str,         len); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
   void print_raw_cr(const char* str)         { write(str, strlen(str)); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
   void print_raw_cr(const char* str, int len){ write(str,         len); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
   void put(char ch);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 1
diff changeset
    88
   void sp(int count = 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
   void cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
   void bol() { if (_position > 0)  cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
   // Time stamp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
   TimeStamp& time_stamp() { return _stamp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
   void stamp();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
    95
   void stamp(bool guard, const char* prefix, const char* suffix);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
    96
   void stamp(bool guard) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
    97
     stamp(guard, "", ": ");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
    98
   }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
   // Date stamp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
   void date_stamp(bool guard, const char* prefix, const char* suffix);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
   // A simplified call that includes a suffix of ": "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
   void date_stamp(bool guard) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
     date_stamp(guard, "", ": ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
   // portable printing of 64 bit integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
   void print_jlong(jlong value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
   void print_julong(julong value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
   // flushing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
   virtual void flush() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
   virtual void write(const char* str, size_t len) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
   virtual ~outputStream() {}  // close properly on deletion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
   void dec_cr() { dec(); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
   void inc_cr() { inc(); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// standard output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
                                // ANSI C++ name collision
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
extern outputStream* tty;           // tty output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
extern outputStream* gclog_or_tty;  // stream for gc log if -Xloggc:<f>, or tty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// advisory locking for the shared tty stream:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
class ttyLocker: StackObj {
8333
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   126
  friend class ttyUnlocker;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  intx _holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static intx  hold_tty();                // returns a "holder" token
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  static void  release_tty(intx holder);  // must witness same token
8333
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   133
  static bool  release_tty_if_locked();   // returns true if lock was released
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static void  break_tty_lock_for_safepoint(intx holder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  ttyLocker()  { _holder = hold_tty(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  ~ttyLocker() { release_tty(_holder); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
8333
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   140
// Release the tty lock if it's held and reacquire it if it was
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   141
// locked.  Used to avoid lock ordering problems.
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   142
class ttyUnlocker: StackObj {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   143
 private:
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   144
  bool _was_locked;
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   145
 public:
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   146
  ttyUnlocker()  {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   147
    _was_locked = ttyLocker::release_tty_if_locked();
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   148
  }
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   149
  ~ttyUnlocker() {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   150
    if (_was_locked) {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   151
      ttyLocker::hold_tty();
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   152
    }
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   153
  }
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   154
};
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   155
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// for writing to strings; buffer will expand automatically
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
class stringStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  char*  buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  size_t buffer_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  size_t buffer_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  bool   buffer_fixed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  stringStream(size_t initial_bufsize = 256);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  stringStream(char* fixed_buffer, size_t fixed_buffer_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  ~stringStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  size_t      size() { return buffer_pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  const char* base() { return buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  void  reset() { buffer_pos = 0; _precount = 0; _position = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  char* as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
class fileStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  FILE* _file;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  bool  _need_close;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  fileStream(const char* file_name);
8114
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   180
  fileStream(const char* file_name, const char* opentype);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  fileStream(FILE* file) { _file = file; _need_close = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  ~fileStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  bool is_open() const { return _file != NULL; }
8114
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   184
  void set_need_close(bool b) { _need_close = b;}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  virtual void write(const char* c, size_t len);
8114
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   186
  size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   187
  char* readln(char *data, int count);
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   188
  int eof() { return feof(_file); }
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   189
  long fileSize();
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   190
  void rewind() { ::rewind(_file); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
// unlike fileStream, fdStream does unbuffered I/O by calling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// open() and write() directly. It is async-safe, but output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
// from multiple thread may be mixed together. Used by fatal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
// error handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
class fdStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  int  _fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  bool _need_close;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  fdStream(const char* file_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  fdStream(int fd = -1) { _fd = fd; _need_close = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  ~fdStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  bool is_open() const { return _fd != -1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  void set_fd(int fd) { _fd = fd; _need_close = false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  int fd() const { return _fd; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  void flush() {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void ostream_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
void ostream_init_log();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
void ostream_exit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
void ostream_abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
// staticBufferStream uses a user-supplied buffer for all formatting.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// Used for safe formatting during fatal error handling.  Not MT safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
// Do not share the stream between multiple threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
class staticBufferStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  char* _buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  size_t _buflen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  outputStream* _outer_stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  staticBufferStream(char* buffer, size_t buflen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
                     outputStream *outer_stream);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  ~staticBufferStream() {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  void print(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void print_cr(const char* format, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  void vprint(const char *format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  void vprint_cr(const char* format, va_list argptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
// In the non-fixed buffer case an underlying buffer will be created and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
// managed in C heap. Not MT-safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
class bufferedStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  char*  buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  size_t buffer_pos;
768
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   244
  size_t buffer_max;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  size_t buffer_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  bool   buffer_fixed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
 public:
768
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   248
  bufferedStream(size_t initial_bufsize = 256, size_t bufmax = 1024*1024*10);
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   249
  bufferedStream(char* fixed_buffer, size_t fixed_buffer_size, size_t bufmax = 1024*1024*10);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  ~bufferedStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  size_t      size() { return buffer_pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  const char* base() { return buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  void  reset() { buffer_pos = 0; _precount = 0; _position = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  char* as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
#define O_BUFLEN 2000   // max size of output of individual print() methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
class networkStream : public bufferedStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    int _socket;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    networkStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    ~networkStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    bool connect(const char *host, short port);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    bool is_open() const { return _socket != -1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    int read(char *buf, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    void close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    virtual void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   279
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   280
#endif // SHARE_VM_UTILITIES_OSTREAM_HPP