src/hotspot/share/utilities/ostream.hpp
author mr
Tue, 29 Oct 2019 13:52:04 -0700
changeset 58850 f4290bf1cc21
parent 55236 c87e52dbdca0
permissions -rw-r--r--
8233137: runtime/ErrorHandling/VeryEarlyAssertTest.java fails after 8232080 Reviewed-by: stuefe, iignatyev, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49980
diff changeset
     2
 * Copyright (c) 1997, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49980
diff changeset
    25
#ifndef SHARE_UTILITIES_OSTREAM_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49980
diff changeset
    26
#define SHARE_UTILITIES_OSTREAM_HPP
7397
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"
35897
beba2418d973 8146793: logStream::write re-formats string
kbarrett
parents: 35869
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
18928
ac0163dd0a50 7143807: ResourceMark nesting problem in stringStream
fparain
parents: 17121
diff changeset
    32
DEBUG_ONLY(class ResourceMark;)
ac0163dd0a50 7143807: ResourceMark nesting problem in stringStream
fparain
parents: 17121
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Output streams for printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Printing guidelines:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Where possible, please use tty->print() and tty->print_cr().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// For product mode VM warnings use warning() which internally uses tty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// In places where tty is not initialized yet or too much overhead,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// we may use jio_printf:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//     jio_fprintf(defaultStream::output_stream(), "Message");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// This allows for redirection via -XX:+DisplayVMOutputToStdout and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// -XX:+DisplayVMOutputToStderr
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class outputStream : public ResourceObj {
54973
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 53931
diff changeset
    45
 private:
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 53931
diff changeset
    46
   outputStream(const outputStream&);
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 53931
diff changeset
    47
   outputStream& operator=(const outputStream&);
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 53931
diff changeset
    48
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
   int _indentation; // current indentation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
   int _width;       // width of the page
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
   int _position;    // position on the current line
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
   int _newlines;    // number of '\n' output so far
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
   julong _precount; // number of chars output, less _position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
   TimeStamp _stamp; // for time stamps
35869
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    56
   char* _scratch;   // internal scratch buffer for printf
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    57
   size_t _scratch_len; // size of internal scratch buffer
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
   void update_position(const char* s, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
   static const char* do_vsnprintf(char* buffer, size_t buflen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
                                   const char* format, va_list ap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                                   bool add_cr,
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23517
diff changeset
    63
                                   size_t& result_len)  ATTRIBUTE_PRINTF(3, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
35869
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    65
   // calls do_vsnprintf and writes output to stream; uses an on-stack buffer.
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    66
   void do_vsnprintf_and_write_with_automatic_buffer(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    67
   // calls do_vsnprintf and writes output to stream; uses the user-provided buffer;
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    68
   void do_vsnprintf_and_write_with_scratch_buffer(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    69
   // calls do_vsnprintf, then writes output to stream.
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    70
   void do_vsnprintf_and_write(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
    71
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
   // creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
   outputStream(int width = 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
   outputStream(int width, bool has_time_stamps);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
   // indentation
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
    78
   outputStream& indent();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
   void inc() { _indentation++; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
   void dec() { _indentation--; };
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
    81
   void inc(int n) { _indentation += n; };
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
    82
   void dec(int n) { _indentation -= n; };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
   int  indentation() const    { return _indentation; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
   void set_indentation(int i) { _indentation = i;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
   void fill_to(int col);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 1
diff changeset
    86
   void move_to(int col, int slop = 6, int min_space = 2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
   // sizing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
   int width()    const { return _width;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
   int position() const { return _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
   int newlines() const { return _newlines; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
   julong count() const { return _precount + _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
   void set_count(julong count) { _precount = count - _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
   void set_position(int pos)   { _position = pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
   // printing
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23517
diff changeset
    97
   void print(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23517
diff changeset
    98
   void print_cr(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23517
diff changeset
    99
   void vprint(const char *format, va_list argptr) ATTRIBUTE_PRINTF(2, 0);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23517
diff changeset
   100
   void vprint_cr(const char* format, va_list argptr) ATTRIBUTE_PRINTF(2, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
   void print_raw(const char* str)            { write(str, strlen(str)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
   void print_raw(const char* str, int len)   { write(str,         len); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
   void print_raw_cr(const char* str)         { write(str, strlen(str)); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
   void print_raw_cr(const char* str, int len){ write(str,         len); cr(); }
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   105
   void print_data(void* data, size_t len, bool with_ascii);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
   void put(char ch);
347
df859fcca515 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 1
diff changeset
   107
   void sp(int count = 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
   void cr();
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents: 47216
diff changeset
   109
   void cr_indent();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
   void bol() { if (_position > 0)  cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
49980
57dd7b4ba338 8201572: Improve Metaspace Statistics
stuefe
parents: 47216
diff changeset
   112
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
   // Time stamp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
   TimeStamp& time_stamp() { return _stamp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
   void stamp();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
   116
   void stamp(bool guard, const char* prefix, const char* suffix);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
   117
   void stamp(bool guard) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
   118
     stamp(guard, "", ": ");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 347
diff changeset
   119
   }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
   // Date stamp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
   void date_stamp(bool guard, const char* prefix, const char* suffix);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
   // A simplified call that includes a suffix of ": "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
   void date_stamp(bool guard) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
     date_stamp(guard, "", ": ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
   // portable printing of 64 bit integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
   void print_jlong(jlong value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
   void print_julong(julong value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
   // flushing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
   virtual void flush() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
   virtual void write(const char* str, size_t len) = 0;
23517
27c4307d6cda 7090324: gclog rotation via external tool
minqi
parents: 22234
diff changeset
   134
   virtual void rotate_log(bool force, outputStream* out = NULL) {} // GC log rotation
9990
c8683968c01b 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 8921
diff changeset
   135
   virtual ~outputStream() {}   // close properly on deletion
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
35869
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
   137
   // Caller may specify their own scratch buffer to use for printing; otherwise,
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
   138
   // an automatic buffer on the stack (with O_BUFLEN len) is used.
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
   139
   void set_scratch_buffer(char* p, size_t len) { _scratch = p; _scratch_len = len; }
cd7df4cdaa1a 8146905: cleanup ostream, staticBufferStream
stuefe
parents: 35061
diff changeset
   140
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
   void dec_cr() { dec(); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
   void inc_cr() { inc(); cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// standard output
9990
c8683968c01b 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 8921
diff changeset
   146
// ANSI C++ name collision
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
extern outputStream* tty;           // tty output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   149
class streamIndentor : public StackObj {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   150
 private:
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   151
  outputStream* _str;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   152
  int _amount;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   153
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   154
 public:
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   155
  streamIndentor(outputStream* str, int amt = 2) : _str(str), _amount(amt) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   156
    _str->inc(_amount);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   157
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   158
  ~streamIndentor() { _str->dec(_amount); }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   159
};
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9990
diff changeset
   160
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// advisory locking for the shared tty stream:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
class ttyLocker: StackObj {
8333
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   163
  friend class ttyUnlocker;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  intx _holder;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  static intx  hold_tty();                // returns a "holder" token
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  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
   170
  static bool  release_tty_if_locked();   // returns true if lock was released
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  static void  break_tty_lock_for_safepoint(intx holder);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  ttyLocker()  { _holder = hold_tty(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  ~ttyLocker() { release_tty(_holder); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
8333
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   177
// 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
   178
// locked.  Used to avoid lock ordering problems.
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   179
class ttyUnlocker: StackObj {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   180
 private:
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   181
  bool _was_locked;
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   182
 public:
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   183
  ttyUnlocker()  {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   184
    _was_locked = ttyLocker::release_tty_if_locked();
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   185
  }
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   186
  ~ttyUnlocker() {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   187
    if (_was_locked) {
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   188
      ttyLocker::hold_tty();
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   189
    }
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   190
  }
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   191
};
11a7f6fc6419 7021531: lock ordering problems after fix for 6354181
never
parents: 8114
diff changeset
   192
54974
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   193
// for writing to strings; buffer will expand automatically.
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   194
// Buffer will always be zero-terminated.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
class stringStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  char*  buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  size_t buffer_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  size_t buffer_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  bool   buffer_fixed;
55236
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   201
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   202
  // zero terminate at buffer_pos.
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   203
  void zero_terminate();
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   204
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
 public:
54974
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   206
  // Create a stringStream using an internal buffer of initially initial_bufsize size;
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   207
  // will be enlarged on demand. There is no maximum cap.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  stringStream(size_t initial_bufsize = 256);
54974
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   209
  // Creates a stringStream using a caller-provided buffer. Will truncate silently if
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   210
  // it overflows.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  stringStream(char* fixed_buffer, size_t fixed_buffer_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  ~stringStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  virtual void write(const char* c, size_t len);
54974
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   214
  // Return number of characters written into buffer, excluding terminating zero and
22961d673487 8224193: stringStream should not use Resouce Area
stuefe
parents: 54973
diff changeset
   215
  // subject to truncation in static buffer mode.
55236
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   216
  size_t      size() const { return buffer_pos; }
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   217
  const char* base() const { return buffer; }
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   218
  void  reset();
c87e52dbdca0 8225225: stringStream internal buffer should always be zero terminated
stuefe
parents: 55023
diff changeset
   219
  char* as_string() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
class fileStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  FILE* _file;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  bool  _need_close;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
 public:
9990
c8683968c01b 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 8921
diff changeset
   227
  fileStream() { _file = NULL; _need_close = false; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  fileStream(const char* file_name);
8114
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   229
  fileStream(const char* file_name, const char* opentype);
17121
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 15803
diff changeset
   230
  fileStream(FILE* file, bool need_close = false) { _file = file; _need_close = need_close; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  ~fileStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  bool is_open() const { return _file != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  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
   234
  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
   235
  char* readln(char *data, int count);
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   236
  int eof() { return feof(_file); }
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   237
  long fileSize();
340b5b8b544b 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 7397
diff changeset
   238
  void rewind() { ::rewind(_file); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25350
diff changeset
   242
CDS_ONLY(extern fileStream*   classlist_file;)
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25350
diff changeset
   243
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// unlike fileStream, fdStream does unbuffered I/O by calling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// open() and write() directly. It is async-safe, but output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// from multiple thread may be mixed together. Used by fatal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// error handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
class fdStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  int  _fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
 public:
53931
f47ca94f30b9 8219630: cleanup hotspot ostream.cpp
mbaesken
parents: 53244
diff changeset
   252
  fdStream(int fd = -1) : _fd(fd) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  bool is_open() const { return _fd != -1; }
53931
f47ca94f30b9 8219630: cleanup hotspot ostream.cpp
mbaesken
parents: 53244
diff changeset
   254
  void set_fd(int fd) { _fd = fd; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  int fd() const { return _fd; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  void flush() {};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
void ostream_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
void ostream_init_log();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
void ostream_exit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
void ostream_abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
// In the non-fixed buffer case an underlying buffer will be created and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
// managed in C heap. Not MT-safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
class bufferedStream : public outputStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  char*  buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  size_t buffer_pos;
768
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   271
  size_t buffer_max;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  size_t buffer_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  bool   buffer_fixed;
55023
d56d8e40b6cd 8220394: bufferedStream does not honor size limit
stuefe
parents: 54974
diff changeset
   274
  bool   truncated;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
 public:
768
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   276
  bufferedStream(size_t initial_bufsize = 256, size_t bufmax = 1024*1024*10);
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 347
diff changeset
   277
  bufferedStream(char* fixed_buffer, size_t fixed_buffer_size, size_t bufmax = 1024*1024*10);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  ~bufferedStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  virtual void write(const char* c, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  size_t      size() { return buffer_pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  const char* base() { return buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  void  reset() { buffer_pos = 0; _precount = 0; _position = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  char* as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
#define O_BUFLEN 2000   // max size of output of individual print() methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
class networkStream : public bufferedStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    int _socket;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    networkStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    ~networkStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    bool connect(const char *host, short port);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    bool is_open() const { return _socket != -1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    int read(char *buf, size_t len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    void close();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    virtual void flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   307
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49980
diff changeset
   308
#endif // SHARE_UTILITIES_OSTREAM_HPP