hotspot/src/share/vm/utilities/ostream.hpp
changeset 35869 cd7df4cdaa1a
parent 35061 be6025ebffea
child 35897 beba2418d973
--- a/hotspot/src/share/vm/utilities/ostream.hpp	Thu Jan 28 02:30:57 2016 +0100
+++ b/hotspot/src/share/vm/utilities/ostream.hpp	Wed Jan 27 11:51:56 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -49,6 +49,8 @@
    int _newlines;    // number of '\n' output so far
    julong _precount; // number of chars output, less _position
    TimeStamp _stamp; // for time stamps
+   char* _scratch;   // internal scratch buffer for printf
+   size_t _scratch_len; // size of internal scratch buffer
 
    void update_position(const char* s, size_t len);
    static const char* do_vsnprintf(char* buffer, size_t buflen,
@@ -56,6 +58,13 @@
                                    bool add_cr,
                                    size_t& result_len)  ATTRIBUTE_PRINTF(3, 0);
 
+   // calls do_vsnprintf and writes output to stream; uses an on-stack buffer.
+   void do_vsnprintf_and_write_with_automatic_buffer(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
+   // calls do_vsnprintf and writes output to stream; uses the user-provided buffer;
+   void do_vsnprintf_and_write_with_scratch_buffer(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
+   // calls do_vsnprintf, then writes output to stream.
+   void do_vsnprintf_and_write(const char* format, va_list ap, bool add_cr) ATTRIBUTE_PRINTF(2, 0);
+
  public:
    // creation
    outputStream(int width = 80);
@@ -119,6 +128,10 @@
    virtual void rotate_log(bool force, outputStream* out = NULL) {} // GC log rotation
    virtual ~outputStream() {}   // close properly on deletion
 
+   // Caller may specify their own scratch buffer to use for printing; otherwise,
+   // an automatic buffer on the stack (with O_BUFLEN len) is used.
+   void set_scratch_buffer(char* p, size_t len) { _scratch = p; _scratch_len = len; }
+
    void dec_cr() { dec(); cr(); }
    void inc_cr() { inc(); cr(); }
 };
@@ -250,26 +263,6 @@
 void ostream_exit();
 void ostream_abort();
 
-// staticBufferStream uses a user-supplied buffer for all formatting.
-// Used for safe formatting during fatal error handling.  Not MT safe.
-// Do not share the stream between multiple threads.
-class staticBufferStream : public outputStream {
- private:
-  char* _buffer;
-  size_t _buflen;
-  outputStream* _outer_stream;
- public:
-  staticBufferStream(char* buffer, size_t buflen,
-                     outputStream *outer_stream);
-  ~staticBufferStream() {};
-  virtual void write(const char* c, size_t len);
-  void flush();
-  void print(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
-  void print_cr(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
-  void vprint(const char *format, va_list argptr) ATTRIBUTE_PRINTF(2, 0);
-  void vprint_cr(const char* format, va_list argptr) ATTRIBUTE_PRINTF(2, 0);
-};
-
 // In the non-fixed buffer case an underlying buffer will be created and
 // managed in C heap. Not MT-safe.
 class bufferedStream : public outputStream {