< prev index next >

src/share/vm/utilities/ostream.hpp

Print this page
rev 4136 : 7116786: RFE: Detailed information on VerifyErrors
Summary: Provide additional detail in VerifyError messages
Reviewed-by: sspitsyn, acorn
   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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  *


  42  protected:
  43    int _indentation; // current indentation
  44    int _width;       // width of the page
  45    int _position;    // position on the current line
  46    int _newlines;    // number of '\n' output so far
  47    julong _precount; // number of chars output, less _position
  48    TimeStamp _stamp; // for time stamps
  49 
  50    void update_position(const char* s, size_t len);
  51    static const char* do_vsnprintf(char* buffer, size_t buflen,
  52                                    const char* format, va_list ap,
  53                                    bool add_cr,
  54                                    size_t& result_len);
  55 
  56  public:
  57    // creation
  58    outputStream(int width = 80);
  59    outputStream(int width, bool has_time_stamps);
  60 
  61    // indentation
  62    void indent();
  63    void inc() { _indentation++; };
  64    void dec() { _indentation--; };


  65    int  indentation() const    { return _indentation; }
  66    void set_indentation(int i) { _indentation = i;    }
  67    void fill_to(int col);
  68    void move_to(int col, int slop = 6, int min_space = 2);
  69 
  70    // sizing
  71    int width()    const { return _width;    }
  72    int position() const { return _position; }
  73    int newlines() const { return _newlines; }
  74    julong count() const { return _precount + _position; }
  75    void set_count(julong count) { _precount = count - _position; }
  76    void set_position(int pos)   { _position = pos; }
  77 
  78    // printing
  79    void print(const char* format, ...);
  80    void print_cr(const char* format, ...);
  81    void vprint(const char *format, va_list argptr);
  82    void vprint_cr(const char* format, va_list argptr);
  83    void print_raw(const char* str)            { write(str, strlen(str)); }
  84    void print_raw(const char* str, int len)   { write(str,         len); }
  85    void print_raw_cr(const char* str)         { write(str, strlen(str)); cr(); }
  86    void print_raw_cr(const char* str, int len){ write(str,         len); cr(); }

  87    void put(char ch);
  88    void sp(int count = 1);
  89    void cr();
  90    void bol() { if (_position > 0)  cr(); }
  91 
  92    // Time stamp
  93    TimeStamp& time_stamp() { return _stamp; }
  94    void stamp();
  95    void stamp(bool guard, const char* prefix, const char* suffix);
  96    void stamp(bool guard) {
  97      stamp(guard, "", ": ");
  98    }
  99    // Date stamp
 100    void date_stamp(bool guard, const char* prefix, const char* suffix);
 101    // A simplified call that includes a suffix of ": "
 102    void date_stamp(bool guard) {
 103      date_stamp(guard, "", ": ");
 104    }
 105 
 106    // portable printing of 64 bit integers
 107    void print_jlong(jlong value);
 108    void print_julong(julong value);
 109 
 110    // flushing
 111    virtual void flush() {}
 112    virtual void write(const char* str, size_t len) = 0;
 113    virtual void rotate_log() {} // GC log rotation
 114    virtual ~outputStream() {}   // close properly on deletion
 115 
 116    void dec_cr() { dec(); cr(); }
 117    void inc_cr() { inc(); cr(); }
 118 };
 119 
 120 // standard output
 121 // ANSI C++ name collision
 122 extern outputStream* tty;           // tty output
 123 extern outputStream* gclog_or_tty;  // stream for gc log if -Xloggc:<f>, or tty













 124 
 125 // advisory locking for the shared tty stream:
 126 class ttyLocker: StackObj {
 127   friend class ttyUnlocker;
 128  private:
 129   intx _holder;
 130 
 131  public:
 132   static intx  hold_tty();                // returns a "holder" token
 133   static void  release_tty(intx holder);  // must witness same token
 134   static bool  release_tty_if_locked();   // returns true if lock was released
 135   static void  break_tty_lock_for_safepoint(intx holder);
 136 
 137   ttyLocker()  { _holder = hold_tty(); }
 138   ~ttyLocker() { release_tty(_holder); }
 139 };
 140 
 141 // Release the tty lock if it's held and reacquire it if it was
 142 // locked.  Used to avoid lock ordering problems.
 143 class ttyUnlocker: StackObj {


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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  *


  42  protected:
  43    int _indentation; // current indentation
  44    int _width;       // width of the page
  45    int _position;    // position on the current line
  46    int _newlines;    // number of '\n' output so far
  47    julong _precount; // number of chars output, less _position
  48    TimeStamp _stamp; // for time stamps
  49 
  50    void update_position(const char* s, size_t len);
  51    static const char* do_vsnprintf(char* buffer, size_t buflen,
  52                                    const char* format, va_list ap,
  53                                    bool add_cr,
  54                                    size_t& result_len);
  55 
  56  public:
  57    // creation
  58    outputStream(int width = 80);
  59    outputStream(int width, bool has_time_stamps);
  60 
  61    // indentation
  62    outputStream& indent();
  63    void inc() { _indentation++; };
  64    void dec() { _indentation--; };
  65    void inc(int n) { _indentation += n; };
  66    void dec(int n) { _indentation -= n; };
  67    int  indentation() const    { return _indentation; }
  68    void set_indentation(int i) { _indentation = i;    }
  69    void fill_to(int col);
  70    void move_to(int col, int slop = 6, int min_space = 2);
  71 
  72    // sizing
  73    int width()    const { return _width;    }
  74    int position() const { return _position; }
  75    int newlines() const { return _newlines; }
  76    julong count() const { return _precount + _position; }
  77    void set_count(julong count) { _precount = count - _position; }
  78    void set_position(int pos)   { _position = pos; }
  79 
  80    // printing
  81    void print(const char* format, ...);
  82    void print_cr(const char* format, ...);
  83    void vprint(const char *format, va_list argptr);
  84    void vprint_cr(const char* format, va_list argptr);
  85    void print_raw(const char* str)            { write(str, strlen(str)); }
  86    void print_raw(const char* str, int len)   { write(str,         len); }
  87    void print_raw_cr(const char* str)         { write(str, strlen(str)); cr(); }
  88    void print_raw_cr(const char* str, int len){ write(str,         len); cr(); }
  89    void print_data(void* data, size_t len, bool with_ascii);
  90    void put(char ch);
  91    void sp(int count = 1);
  92    void cr();
  93    void bol() { if (_position > 0)  cr(); }
  94 
  95    // Time stamp
  96    TimeStamp& time_stamp() { return _stamp; }
  97    void stamp();
  98    void stamp(bool guard, const char* prefix, const char* suffix);
  99    void stamp(bool guard) {
 100      stamp(guard, "", ": ");
 101    }
 102    // Date stamp
 103    void date_stamp(bool guard, const char* prefix, const char* suffix);
 104    // A simplified call that includes a suffix of ": "
 105    void date_stamp(bool guard) {
 106      date_stamp(guard, "", ": ");
 107    }
 108 
 109    // portable printing of 64 bit integers
 110    void print_jlong(jlong value);
 111    void print_julong(julong value);
 112 
 113    // flushing
 114    virtual void flush() {}
 115    virtual void write(const char* str, size_t len) = 0;
 116    virtual void rotate_log() {} // GC log rotation
 117    virtual ~outputStream() {}   // close properly on deletion
 118 
 119    void dec_cr() { dec(); cr(); }
 120    void inc_cr() { inc(); cr(); }
 121 };
 122 
 123 // standard output
 124 // ANSI C++ name collision
 125 extern outputStream* tty;           // tty output
 126 extern outputStream* gclog_or_tty;  // stream for gc log if -Xloggc:<f>, or tty
 127 
 128 class streamIndentor : public StackObj {
 129  private:
 130   outputStream* _str;
 131   int _amount;
 132 
 133  public:
 134   streamIndentor(outputStream* str, int amt = 2) : _str(str), _amount(amt) {
 135     _str->inc(_amount);
 136   }
 137   ~streamIndentor() { _str->dec(_amount); }
 138 };
 139 
 140 
 141 // advisory locking for the shared tty stream:
 142 class ttyLocker: StackObj {
 143   friend class ttyUnlocker;
 144  private:
 145   intx _holder;
 146 
 147  public:
 148   static intx  hold_tty();                // returns a "holder" token
 149   static void  release_tty(intx holder);  // must witness same token
 150   static bool  release_tty_if_locked();   // returns true if lock was released
 151   static void  break_tty_lock_for_safepoint(intx holder);
 152 
 153   ttyLocker()  { _holder = hold_tty(); }
 154   ~ttyLocker() { release_tty(_holder); }
 155 };
 156 
 157 // Release the tty lock if it's held and reacquire it if it was
 158 // locked.  Used to avoid lock ordering problems.
 159 class ttyUnlocker: StackObj {


< prev index next >