Mercurial > hg > graal-jvmci-8
comparison src/share/vm/utilities/debug.hpp @ 4872:aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
Reviewed-by: kvn, jrose, kevinw, brutisso, twisti, jmasa
author | never |
---|---|
date | Wed, 01 Feb 2012 07:59:01 -0800 |
parents | 1d1603768966 |
children | 6c5b7a6becc8 |
comparison
equal
deleted
inserted
replaced
4871:f067b4e0e04b | 4872:aa3d708d67c4 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. | 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. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
31 #include <stdarg.h> | 31 #include <stdarg.h> |
32 | 32 |
33 // Simple class to format the ctor arguments into a fixed-sized buffer. | 33 // Simple class to format the ctor arguments into a fixed-sized buffer. |
34 template <size_t bufsz = 256> | 34 template <size_t bufsz = 256> |
35 class FormatBuffer { | 35 class FormatBuffer { |
36 public: | 36 public: |
37 inline FormatBuffer(const char * format, ...); | 37 inline FormatBuffer(const char * format, ...); |
38 inline void append(const char* format, ...); | 38 inline void append(const char* format, ...); |
39 inline void print(const char* format, ...); | |
40 inline void printv(const char* format, va_list ap); | |
39 operator const char *() const { return _buf; } | 41 operator const char *() const { return _buf; } |
40 | 42 |
41 private: | 43 char* buffer() { return _buf; } |
44 int size() { return bufsz; } | |
45 | |
46 private: | |
42 FormatBuffer(const FormatBuffer &); // prevent copies | 47 FormatBuffer(const FormatBuffer &); // prevent copies |
43 | 48 |
44 private: | 49 protected: |
45 char _buf[bufsz]; | 50 char _buf[bufsz]; |
51 | |
52 inline FormatBuffer(); | |
46 }; | 53 }; |
47 | 54 |
48 template <size_t bufsz> | 55 template <size_t bufsz> |
49 FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) { | 56 FormatBuffer<bufsz>::FormatBuffer(const char * format, ...) { |
50 va_list argp; | 57 va_list argp; |
51 va_start(argp, format); | 58 va_start(argp, format); |
52 jio_vsnprintf(_buf, bufsz, format, argp); | 59 jio_vsnprintf(_buf, bufsz, format, argp); |
53 va_end(argp); | 60 va_end(argp); |
61 } | |
62 | |
63 template <size_t bufsz> | |
64 FormatBuffer<bufsz>::FormatBuffer() { | |
65 _buf[0] = '\0'; | |
66 } | |
67 | |
68 template <size_t bufsz> | |
69 void FormatBuffer<bufsz>::print(const char * format, ...) { | |
70 va_list argp; | |
71 va_start(argp, format); | |
72 jio_vsnprintf(_buf, bufsz, format, argp); | |
73 va_end(argp); | |
74 } | |
75 | |
76 template <size_t bufsz> | |
77 void FormatBuffer<bufsz>::printv(const char * format, va_list argp) { | |
78 jio_vsnprintf(_buf, bufsz, format, argp); | |
54 } | 79 } |
55 | 80 |
56 template <size_t bufsz> | 81 template <size_t bufsz> |
57 void FormatBuffer<bufsz>::append(const char* format, ...) { | 82 void FormatBuffer<bufsz>::append(const char* format, ...) { |
58 // Given that the constructor does a vsnprintf we can assume that | 83 // Given that the constructor does a vsnprintf we can assume that |