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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "compiler/compileLog.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "prims/jvm.h"
29 #include "runtime/arguments.hpp"
30 #include "runtime/os.hpp"
31 #include "runtime/vm_version.hpp"
32 #include "utilities/defaultStream.hpp"
33 #include "utilities/macros.hpp"
34 #include "utilities/ostream.hpp"
35 #include "utilities/xmlstream.hpp"
36
37 extern "C" void jio_print(const char* s); // Declarationtion of jvm method
38
39 outputStream::outputStream(int width) {
40 _width = width;
41 _position = 0;
42 _newlines = 0;
43 _precount = 0;
44 _indentation = 0;
45 _scratch = NULL;
46 _scratch_len = 0;
47 }
48
49 outputStream::outputStream(int width, bool has_time_stamps) {
50 _width = width;
51 _position = 0;
52 _newlines = 0;
53 _precount = 0;
54 _indentation = 0;
579 int defaultStream::_output_fd = 1;
580 int defaultStream::_error_fd = 2;
581 FILE* defaultStream::_output_stream = stdout;
582 FILE* defaultStream::_error_stream = stderr;
583
584 #define LOG_MAJOR_VERSION 160
585 #define LOG_MINOR_VERSION 1
586
587 void defaultStream::init() {
588 _inited = true;
589 if (LogVMOutput || LogCompilation) {
590 init_log();
591 }
592 }
593
594 bool defaultStream::has_log_file() {
595 // lazily create log file (at startup, LogVMOutput is false even
596 // if +LogVMOutput is used, because the flags haven't been parsed yet)
597 // For safer printing during fatal error handling, do not init logfile
598 // if a VM error has been reported.
599 if (!_inited && !is_error_reported()) init();
600 return _log_file != NULL;
601 }
602
603 fileStream* defaultStream::open_file(const char* log_name) {
604 const char* try_name = make_log_name(log_name, NULL);
605 if (try_name == NULL) {
606 warning("Cannot open file %s: file name is too long.\n", log_name);
607 return NULL;
608 }
609
610 fileStream* file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name);
611 FREE_C_HEAP_ARRAY(char, try_name);
612 if (file->is_open()) {
613 return file;
614 }
615
616 // Try again to open the file in the temp directory.
617 delete file;
618 char warnbuf[O_BUFLEN*2];
619 jio_snprintf(warnbuf, sizeof(warnbuf), "Warning: Cannot open log file: %s\n", log_name);
771 // delete file;
772 }
773 }
774 }
775
776 intx defaultStream::hold(intx writer_id) {
777 bool has_log = has_log_file(); // check before locking
778 if (// impossible, but who knows?
779 writer_id == NO_WRITER ||
780
781 // bootstrap problem
782 tty_lock == NULL ||
783
784 // can't grab a lock if current Thread isn't set
785 Thread::current_or_null() == NULL ||
786
787 // developer hook
788 !SerializeVMOutput ||
789
790 // VM already unhealthy
791 is_error_reported() ||
792
793 // safepoint == global lock (for VM only)
794 (SafepointSynchronize::is_synchronizing() &&
795 Thread::current()->is_VM_thread())
796 ) {
797 // do not attempt to lock unless we know the thread and the VM is healthy
798 return NO_WRITER;
799 }
800 if (_writer == writer_id) {
801 // already held, no need to re-grab the lock
802 return NO_WRITER;
803 }
804 tty_lock->lock_without_safepoint_check();
805 // got the lock
806 if (writer_id != _last_writer) {
807 if (has_log) {
808 _log_file->bol();
809 // output a hint where this output is coming from:
810 _log_file->print_cr("<writer thread='" UINTX_FORMAT "'/>", writer_id);
811 }
|
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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "compiler/compileLog.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "prims/jvm.h"
29 #include "runtime/arguments.hpp"
30 #include "runtime/os.hpp"
31 #include "runtime/vm_version.hpp"
32 #include "utilities/defaultStream.hpp"
33 #include "utilities/macros.hpp"
34 #include "utilities/ostream.hpp"
35 #include "utilities/vmError.hpp"
36 #include "utilities/xmlstream.hpp"
37
38 extern "C" void jio_print(const char* s); // Declarationtion of jvm method
39
40 outputStream::outputStream(int width) {
41 _width = width;
42 _position = 0;
43 _newlines = 0;
44 _precount = 0;
45 _indentation = 0;
46 _scratch = NULL;
47 _scratch_len = 0;
48 }
49
50 outputStream::outputStream(int width, bool has_time_stamps) {
51 _width = width;
52 _position = 0;
53 _newlines = 0;
54 _precount = 0;
55 _indentation = 0;
580 int defaultStream::_output_fd = 1;
581 int defaultStream::_error_fd = 2;
582 FILE* defaultStream::_output_stream = stdout;
583 FILE* defaultStream::_error_stream = stderr;
584
585 #define LOG_MAJOR_VERSION 160
586 #define LOG_MINOR_VERSION 1
587
588 void defaultStream::init() {
589 _inited = true;
590 if (LogVMOutput || LogCompilation) {
591 init_log();
592 }
593 }
594
595 bool defaultStream::has_log_file() {
596 // lazily create log file (at startup, LogVMOutput is false even
597 // if +LogVMOutput is used, because the flags haven't been parsed yet)
598 // For safer printing during fatal error handling, do not init logfile
599 // if a VM error has been reported.
600 if (!_inited && !VMError::is_error_reported()) init();
601 return _log_file != NULL;
602 }
603
604 fileStream* defaultStream::open_file(const char* log_name) {
605 const char* try_name = make_log_name(log_name, NULL);
606 if (try_name == NULL) {
607 warning("Cannot open file %s: file name is too long.\n", log_name);
608 return NULL;
609 }
610
611 fileStream* file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name);
612 FREE_C_HEAP_ARRAY(char, try_name);
613 if (file->is_open()) {
614 return file;
615 }
616
617 // Try again to open the file in the temp directory.
618 delete file;
619 char warnbuf[O_BUFLEN*2];
620 jio_snprintf(warnbuf, sizeof(warnbuf), "Warning: Cannot open log file: %s\n", log_name);
772 // delete file;
773 }
774 }
775 }
776
777 intx defaultStream::hold(intx writer_id) {
778 bool has_log = has_log_file(); // check before locking
779 if (// impossible, but who knows?
780 writer_id == NO_WRITER ||
781
782 // bootstrap problem
783 tty_lock == NULL ||
784
785 // can't grab a lock if current Thread isn't set
786 Thread::current_or_null() == NULL ||
787
788 // developer hook
789 !SerializeVMOutput ||
790
791 // VM already unhealthy
792 VMError::is_error_reported() ||
793
794 // safepoint == global lock (for VM only)
795 (SafepointSynchronize::is_synchronizing() &&
796 Thread::current()->is_VM_thread())
797 ) {
798 // do not attempt to lock unless we know the thread and the VM is healthy
799 return NO_WRITER;
800 }
801 if (_writer == writer_id) {
802 // already held, no need to re-grab the lock
803 return NO_WRITER;
804 }
805 tty_lock->lock_without_safepoint_check();
806 // got the lock
807 if (writer_id != _last_writer) {
808 if (has_log) {
809 _log_file->bol();
810 // output a hint where this output is coming from:
811 _log_file->print_cr("<writer thread='" UINTX_FORMAT "'/>", writer_id);
812 }
|