< prev index next >

src/hotspot/share/utilities/ostream.cpp

Print this page
rev 59277 : [mq]: v3


  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "compiler/compileLog.hpp"
  28 #include "memory/allocation.inline.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/arguments.hpp"
  31 #include "runtime/os.inline.hpp"

  32 #include "runtime/vm_version.hpp"
  33 #include "utilities/defaultStream.hpp"
  34 #include "utilities/macros.hpp"
  35 #include "utilities/ostream.hpp"
  36 #include "utilities/vmError.hpp"
  37 #include "utilities/xmlstream.hpp"
  38 
  39 // Declarations of jvm methods
  40 extern "C" void jio_print(const char* s, size_t len);
  41 extern "C" int jio_printf(const char *fmt, ...);
  42 
  43 outputStream::outputStream(int width) {
  44   _width       = width;
  45   _position    = 0;
  46   _newlines    = 0;
  47   _precount    = 0;
  48   _indentation = 0;
  49   _scratch     = NULL;
  50   _scratch_len = 0;
  51 }


 351     zero_terminate();
 352   }
 353 
 354   // Note that the following does not depend on write_len.
 355   // This means that position and count get updated
 356   // even when overflow occurs.
 357   update_position(s, len);
 358 }
 359 
 360 void stringStream::zero_terminate() {
 361   assert(buffer != NULL &&
 362          buffer_pos < buffer_length, "sanity");
 363   buffer[buffer_pos] = '\0';
 364 }
 365 
 366 void stringStream::reset() {
 367   buffer_pos = 0; _precount = 0; _position = 0;
 368   zero_terminate();
 369 }
 370 
 371 char* stringStream::as_string() const {
 372   char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1);

 373   strncpy(copy, buffer, buffer_pos);
 374   copy[buffer_pos] = 0;  // terminating null





 375   return copy;
 376 }
 377 
 378 stringStream::~stringStream() {
 379   if (buffer_fixed == false && buffer != NULL) {
 380     FREE_C_HEAP_ARRAY(char, buffer);
 381   }
 382 }
 383 
 384 xmlStream*   xtty;
 385 outputStream* tty;
 386 CDS_ONLY(fileStream* classlist_file;) // Only dump the classes that can be stored into the CDS archive
 387 extern Mutex* tty_lock;
 388 
 389 #define EXTRACHARLEN   32
 390 #define CURRENTAPPX    ".current"
 391 // convert YYYY-MM-DD HH:MM:SS to YYYY-MM-DD_HH-MM-SS
 392 char* get_datetime_string(char *buf, size_t len) {
 393   os::local_time_string(buf, len);
 394   int i = (int)strlen(buf);




  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "compiler/compileLog.hpp"
  28 #include "memory/allocation.inline.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/arguments.hpp"
  31 #include "runtime/os.inline.hpp"
  32 #include "runtime/orderAccess.hpp"
  33 #include "runtime/vm_version.hpp"
  34 #include "utilities/defaultStream.hpp"
  35 #include "utilities/macros.hpp"
  36 #include "utilities/ostream.hpp"
  37 #include "utilities/vmError.hpp"
  38 #include "utilities/xmlstream.hpp"
  39 
  40 // Declarations of jvm methods
  41 extern "C" void jio_print(const char* s, size_t len);
  42 extern "C" int jio_printf(const char *fmt, ...);
  43 
  44 outputStream::outputStream(int width) {
  45   _width       = width;
  46   _position    = 0;
  47   _newlines    = 0;
  48   _precount    = 0;
  49   _indentation = 0;
  50   _scratch     = NULL;
  51   _scratch_len = 0;
  52 }


 352     zero_terminate();
 353   }
 354 
 355   // Note that the following does not depend on write_len.
 356   // This means that position and count get updated
 357   // even when overflow occurs.
 358   update_position(s, len);
 359 }
 360 
 361 void stringStream::zero_terminate() {
 362   assert(buffer != NULL &&
 363          buffer_pos < buffer_length, "sanity");
 364   buffer[buffer_pos] = '\0';
 365 }
 366 
 367 void stringStream::reset() {
 368   buffer_pos = 0; _precount = 0; _position = 0;
 369   zero_terminate();
 370 }
 371 
 372 char* stringStream::as_string(bool c_heap) const {
 373   char* copy = c_heap ?
 374     NEW_C_HEAP_ARRAY(char, buffer_pos + 1, mtInternal) : NEW_RESOURCE_ARRAY(char, buffer_pos + 1);
 375   strncpy(copy, buffer, buffer_pos);
 376   copy[buffer_pos] = 0;  // terminating null
 377   if (c_heap) {
 378     // Need to ensure our content is written to memory before we return
 379     // the pointer to it.
 380     OrderAccess::storestore();
 381   }
 382   return copy;
 383 }
 384 
 385 stringStream::~stringStream() {
 386   if (buffer_fixed == false && buffer != NULL) {
 387     FREE_C_HEAP_ARRAY(char, buffer);
 388   }
 389 }
 390 
 391 xmlStream*   xtty;
 392 outputStream* tty;
 393 CDS_ONLY(fileStream* classlist_file;) // Only dump the classes that can be stored into the CDS archive
 394 extern Mutex* tty_lock;
 395 
 396 #define EXTRACHARLEN   32
 397 #define CURRENTAPPX    ".current"
 398 // convert YYYY-MM-DD HH:MM:SS to YYYY-MM-DD_HH-MM-SS
 399 char* get_datetime_string(char *buf, size_t len) {
 400   os::local_time_string(buf, len);
 401   int i = (int)strlen(buf);


< prev index next >