src/share/vm/utilities/defaultStream.hpp

Tue, 09 Apr 2013 09:54:17 -0700

author
iignatyev
date
Tue, 09 Apr 2013 09:54:17 -0700
changeset 4908
b84fd7d73702
parent 2314
f95d63e2154a
child 6876
710a3c8b516e
child 7448
a4fdab16b621
permissions
-rw-r--r--

8007288: Additional WB API for compiler's testing
Reviewed-by: kvn, vlivanov

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_UTILITIES_DEFAULTSTREAM_HPP
stefank@2314 26 #define SHARE_VM_UTILITIES_DEFAULTSTREAM_HPP
stefank@2314 27
stefank@2314 28 #include "utilities/xmlstream.hpp"
stefank@2314 29
duke@435 30 class defaultStream : public xmlTextStream {
duke@435 31 friend void ostream_abort();
duke@435 32 public:
duke@435 33 enum { NO_WRITER = -1 };
duke@435 34 private:
duke@435 35 bool _inited;
duke@435 36 fileStream* _log_file; // XML-formatted file shared by all threads
duke@435 37 static int _output_fd;
duke@435 38 static int _error_fd;
duke@435 39 static FILE* _output_stream;
duke@435 40 static FILE* _error_stream;
duke@435 41
duke@435 42 void init();
duke@435 43 void init_log();
duke@435 44 void finish_log();
duke@435 45 void finish_log_on_error(char *buf, int buflen);
duke@435 46 public:
duke@435 47 // must defer time stamp due to the fact that os::init() hasn't
duke@435 48 // yet been called and os::elapsed_counter() may not be valid
duke@435 49 defaultStream() {
duke@435 50 _log_file = NULL;
duke@435 51 _inited = false;
duke@435 52 _writer = -1;
duke@435 53 _last_writer = -1;
duke@435 54 }
duke@435 55
duke@435 56 ~defaultStream() {
duke@435 57 if (has_log_file()) finish_log();
duke@435 58 }
duke@435 59
duke@435 60 static inline FILE* output_stream() {
duke@435 61 return DisplayVMOutputToStderr ? _error_stream : _output_stream;
duke@435 62 }
duke@435 63 static inline FILE* error_stream() {
duke@435 64 return DisplayVMOutputToStdout ? _output_stream : _error_stream;
duke@435 65 }
duke@435 66 static inline int output_fd() {
duke@435 67 return DisplayVMOutputToStderr ? _error_fd : _output_fd;
duke@435 68 }
duke@435 69 static inline int error_fd() {
duke@435 70 return DisplayVMOutputToStdout ? _output_fd : _error_fd;
duke@435 71 }
duke@435 72
duke@435 73 virtual void write(const char* s, size_t len);
duke@435 74
duke@435 75 void flush() {
duke@435 76 // once we can determine whether we are in a signal handler, we
duke@435 77 // should add the following assert here:
duke@435 78 // assert(xxxxxx, "can not flush buffer inside signal handler");
duke@435 79 xmlTextStream::flush();
duke@435 80 fflush(output_stream());
duke@435 81 if (has_log_file()) _log_file->flush();
duke@435 82 }
duke@435 83
duke@435 84 // advisory lock/unlock of _writer field:
duke@435 85 private:
duke@435 86 intx _writer; // thread_id with current rights to output
duke@435 87 intx _last_writer;
duke@435 88 public:
duke@435 89 intx hold(intx writer_id);
duke@435 90 void release(intx holder);
duke@435 91 intx writer() { return _writer; }
duke@435 92 bool has_log_file();
duke@435 93
duke@435 94 static defaultStream* instance; // sole instance
duke@435 95 };
stefank@2314 96
stefank@2314 97 #endif // SHARE_VM_UTILITIES_DEFAULTSTREAM_HPP

mercurial