src/share/vm/utilities/debug.hpp

changeset 3971
6c5b7a6becc8
parent 3499
aa3d708d67c4
child 4037
da91efe96a93
     1.1 --- a/src/share/vm/utilities/debug.hpp	Fri Jul 27 16:14:15 2012 -0700
     1.2 +++ b/src/share/vm/utilities/debug.hpp	Mon Jul 30 09:49:25 2012 -0700
     1.3 @@ -31,29 +31,43 @@
     1.4  #include <stdarg.h>
     1.5  
     1.6  // Simple class to format the ctor arguments into a fixed-sized buffer.
     1.7 +class FormatBufferBase {
     1.8 + protected:
     1.9 +  char* _buf;
    1.10 +  inline FormatBufferBase(char* buf) : _buf(buf) {}
    1.11 + public:
    1.12 +  operator const char *() const { return _buf; }
    1.13 +};
    1.14 +
    1.15 +// Use resource area for buffer
    1.16 +#define RES_BUFSZ 256
    1.17 +class FormatBufferResource : public FormatBufferBase {
    1.18 + public:
    1.19 +  FormatBufferResource(const char * format, ...);
    1.20 +};
    1.21 +
    1.22 +// Use stack for buffer
    1.23  template <size_t bufsz = 256>
    1.24 -class FormatBuffer {
    1.25 +class FormatBuffer : public FormatBufferBase {
    1.26   public:
    1.27    inline FormatBuffer(const char * format, ...);
    1.28    inline void append(const char* format, ...);
    1.29    inline void print(const char* format, ...);
    1.30    inline void printv(const char* format, va_list ap);
    1.31 -  operator const char *() const { return _buf; }
    1.32  
    1.33    char* buffer() { return _buf; }
    1.34    int size() { return bufsz; }
    1.35  
    1.36   private:
    1.37    FormatBuffer(const FormatBuffer &); // prevent copies
    1.38 +  char _buffer[bufsz];
    1.39  
    1.40   protected:
    1.41 -  char _buf[bufsz];
    1.42 -
    1.43    inline FormatBuffer();
    1.44  };
    1.45  
    1.46  template <size_t bufsz>
    1.47 -FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) {
    1.48 +FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) : FormatBufferBase(_buffer) {
    1.49    va_list argp;
    1.50    va_start(argp, format);
    1.51    jio_vsnprintf(_buf, bufsz, format, argp);
    1.52 @@ -61,7 +75,7 @@
    1.53  }
    1.54  
    1.55  template <size_t bufsz>
    1.56 -FormatBuffer<bufsz>::FormatBuffer() {
    1.57 +FormatBuffer<bufsz>::FormatBuffer() : FormatBufferBase(_buffer) {
    1.58    _buf[0] = '\0';
    1.59  }
    1.60  
    1.61 @@ -93,6 +107,7 @@
    1.62  
    1.63  // Used to format messages for assert(), guarantee(), fatal(), etc.
    1.64  typedef FormatBuffer<> err_msg;
    1.65 +typedef FormatBufferResource err_msg_res;
    1.66  
    1.67  // assertions
    1.68  #ifdef ASSERT

mercurial