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_UTILITIES_OSTREAM_HPP
26 #define SHARE_UTILITIES_OSTREAM_HPP
27
28 #include "memory/allocation.hpp"
29 #include "runtime/timer.hpp"
30 #include "utilities/globalDefinitions.hpp"
31
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 private:
46 outputStream(const outputStream&);
47 outputStream& operator=(const outputStream&);
48
49 protected:
50 int _indentation; // current indentation
51 int _width; // width of the page
52 int _position; // position on the current line
53 int _newlines; // number of '\n' output so far
54 julong _precount; // number of chars output, less _position
55 TimeStamp _stamp; // for time stamps
56 char* _scratch; // internal scratch buffer for printf
57 size_t _scratch_len; // size of internal scratch buffer
58
59 void update_position(const char* s, size_t len);
60 static const char* do_vsnprintf(char* buffer, size_t buflen,
61 const char* format, va_list ap,
62 bool add_cr,
63 size_t& result_len) ATTRIBUTE_PRINTF(3, 0);
64
65 // calls do_vsnprintf and writes output to stream; uses an on-stack buffer.
66 void do_vsnprintf_and_write_with_automatic_buffer(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
67 // calls do_vsnprintf and writes output to stream; uses the user-provided buffer;
|
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_UTILITIES_OSTREAM_HPP
26 #define SHARE_UTILITIES_OSTREAM_HPP
27
28 #include "memory/allocation.hpp"
29 #include "runtime/timer.hpp"
30 #include "utilities/globalDefinitions.hpp"
31 #include "utilities/macros.hpp"
32
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 private:
47 NONCOPYABLE(outputStream);
48
49 protected:
50 int _indentation; // current indentation
51 int _width; // width of the page
52 int _position; // position on the current line
53 int _newlines; // number of '\n' output so far
54 julong _precount; // number of chars output, less _position
55 TimeStamp _stamp; // for time stamps
56 char* _scratch; // internal scratch buffer for printf
57 size_t _scratch_len; // size of internal scratch buffer
58
59 void update_position(const char* s, size_t len);
60 static const char* do_vsnprintf(char* buffer, size_t buflen,
61 const char* format, va_list ap,
62 bool add_cr,
63 size_t& result_len) ATTRIBUTE_PRINTF(3, 0);
64
65 // calls do_vsnprintf and writes output to stream; uses an on-stack buffer.
66 void do_vsnprintf_and_write_with_automatic_buffer(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
67 // calls do_vsnprintf and writes output to stream; uses the user-provided buffer;
|