ostream.cpp revision 80
0N/A * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A#
include "incls/_precompiled.incl" 0N/Aextern "C" void jio_print(
const char* s);
// Declarationtion of jvm method 0N/A _precount -=
7;
// invariant: _precount + _position == total count 0N/A// Execute a vsprintf, using the given buffer if necessary. 0N/A// Return a pointer to the formatted string. 0N/A // constant format string 0N/A // trivial copy-through format string assert(
ch != 0,
"please fix call site");
char buf[] = {
ch,
'\0' };
// outputStream::stamp() may get called by ostream_abort(), use snprintf // to avoid allocating large stack buffer in print(). static const char error_time[] =
"yyyy-mm-ddThh:mm:ss.mmm+zzzz";
// N.B. Same as INT64_FORMAT // N.B. Same as UINT64_FORMAT // useful for output to fixed chunks of memory, such as performance counters // if buffer cannot resize, silently truncate // For small overruns, double the buffer. For larger ones, // increase to the requested size. // invariant: buffer is always null-terminated // Note that the following does not depend on write_len. // This means that position and count get updated // even when overflow occurs. // lazily create log file (at startup, LogVMOutput is false even // if +LogVMOutput is used, because the flags haven't been parsed yet) // For safer printing during fatal error handling, do not init logfile // if a VM error has been reported. // convert foo*bar.log to foo123bar.log // %%% Need a MutexLocker? // Try again to open the file. // Note: This feature is for maintainer use only. No need for L10N. xs->
print_cr(
"<?xml version='1.0' encoding='UTF-8'?>");
// (For now, don't bother to issue a DTD for this private format.) // %%% Should be: jlong time_ms = os::start_time_milliseconds(), if // we ever get round to introduce that method on the os class xs->
head(
"hotspot_log version='%d %d'" // Write VM version header immediately. // Record information about the command-line invocation. xs->
head(
"vm_arguments");
// Cf. Arguments::print_on() // Print it as a java-style property list. // System properties don't generally contain newlines, so don't bother with unparsing. // tty output per se is grouped under the <tty>...</tty> element. // All further non-markup text gets copied to the tty: xs->
_text =
this;
// requires friend declaration! // and leave xtty as NULL // finish_log() is called during normal VM shutdown. finish_log_on_error() is // called by ostream_abort() after a fatal error. // Other log forks are appended here, at the End of Time: // Other log forks are appended here, at the End of Time: // Can't delete or close the file because delete and fclose aren't // async-safe. We are about to die, so leave it to the kernel. if (
// impossible, but who knows? // can't grab a lock or call Thread::current() if TLS isn't initialized // safepoint == global lock (for VM only) // do not attempt to lock unless we know the thread and the VM is healthy // already held, no need to re-grab the lock // output a hint where this output is coming from: // nothing to release: either a recursive lock, or we scribbled (too bad) return;
// already unlocked, perhaps via break_tty_lock_for_safepoint // Yuck: jio_print does not accept char*/len. // print to output stream. It can be redirected by a vfprintf hook // flush the log file too, if there were any newlines // (else there was no lock to break) // We want to ensure that time stamps in GC logs consider time 0 // the time when the JVM is initialized, not the first time we ask // for a time stamp. So, here, we explicitly update the time stamp // Note : this must be called AFTER ostream_init() // now we update the time stamp of the GC log to be synced up // If we haven't lazily initialized the logfile yet, do it now, // to avoid the possibility of lazy initialization during a VM // crash, which can affect the stability of the fatal error handler. // ostream_exit() is called during normal VM exit to finish log files, flush // output and free resource. // we temporaly disable PrintMallocFree here // as otherwise it'll lead to using of almost deleted // tty or defaultStream::instance in logging facility // of HeapFree(), see 6391258 // ostream_abort() is called by os::abort() when VM is about to die. // Here we can't delete gclog_or_tty and tty, just flush their output // if buffer cannot resize, silently truncate // For small overruns, double the buffer. For larger ones, // increase to the requested size. assert(
false,
"Socket could not be created!");