220 void outputStream::date_stamp(bool guard,
221 const char* prefix,
222 const char* suffix) {
223 if (!guard) {
224 return;
225 }
226 print_raw(prefix);
227 static const char error_time[] = "yyyy-mm-ddThh:mm:ss.mmm+zzzz";
228 static const int buffer_length = 32;
229 char buffer[buffer_length];
230 const char* iso8601_result = os::iso8601_time(buffer, buffer_length);
231 if (iso8601_result != NULL) {
232 print_raw(buffer);
233 } else {
234 print_raw(error_time);
235 }
236 print_raw(suffix);
237 return;
238 }
239
240 void outputStream::indent() {
241 while (_position < _indentation) sp();
242 }
243
244 void outputStream::print_jlong(jlong value) {
245 // N.B. Same as INT64_FORMAT
246 print(os::jlong_format_specifier(), value);
247 }
248
249 void outputStream::print_julong(julong value) {
250 // N.B. Same as UINT64_FORMAT
251 print(os::julong_format_specifier(), value);
252 }
253
254 stringStream::stringStream(size_t initial_size) : outputStream() {
255 buffer_length = initial_size;
256 buffer = NEW_RESOURCE_ARRAY(char, buffer_length);
257 buffer_pos = 0;
258 buffer_fixed = false;
259 }
260
261 // useful for output to fixed chunks of memory, such as performance counters
262 stringStream::stringStream(char* fixed_buffer, size_t fixed_buffer_size) : outputStream() {
263 buffer_length = fixed_buffer_size;
264 buffer = fixed_buffer;
265 buffer_pos = 0;
266 buffer_fixed = true;
267 }
268
269 void stringStream::write(const char* s, size_t len) {
270 size_t write_len = len; // number of non-null bytes to write
271 size_t end = buffer_pos + len + 1; // position after write and final '\0'
|
220 void outputStream::date_stamp(bool guard,
221 const char* prefix,
222 const char* suffix) {
223 if (!guard) {
224 return;
225 }
226 print_raw(prefix);
227 static const char error_time[] = "yyyy-mm-ddThh:mm:ss.mmm+zzzz";
228 static const int buffer_length = 32;
229 char buffer[buffer_length];
230 const char* iso8601_result = os::iso8601_time(buffer, buffer_length);
231 if (iso8601_result != NULL) {
232 print_raw(buffer);
233 } else {
234 print_raw(error_time);
235 }
236 print_raw(suffix);
237 return;
238 }
239
240 outputStream& outputStream::indent() {
241 while (_position < _indentation) sp();
242 return *this;
243 }
244
245 void outputStream::print_jlong(jlong value) {
246 // N.B. Same as INT64_FORMAT
247 print(os::jlong_format_specifier(), value);
248 }
249
250 void outputStream::print_julong(julong value) {
251 // N.B. Same as UINT64_FORMAT
252 print(os::julong_format_specifier(), value);
253 }
254
255 /**
256 * This prints out hex data in a 'windbg' or 'xxd' form, where each line is:
257 * <hex-address>: 8 * <hex-halfword> <ascii translation (optional)>
258 * example:
259 * 0000000: 7f44 4f46 0102 0102 0000 0000 0000 0000 .DOF............
260 * 0000010: 0000 0000 0000 0040 0000 0020 0000 0005 .......@... ....
261 * 0000020: 0000 0000 0000 0040 0000 0000 0000 015d .......@.......]
262 * ...
263 *
264 * indent is applied to each line. Ends with a CR.
265 */
266 void outputStream::print_data(void* data, size_t len, bool with_ascii) {
267 size_t limit = (len + 16) / 16 * 16;
268 for (size_t i = 0; i < limit; ++i) {
269 if (i % 16 == 0) {
270 indent().print("%07x:", i);
271 }
272 if (i % 2 == 0) {
273 print(" ");
274 }
275 if (i < len) {
276 print("%02x", ((unsigned char*)data)[i]);
277 } else {
278 print(" ");
279 }
280 if ((i + 1) % 16 == 0) {
281 if (with_ascii) {
282 print(" ");
283 for (size_t j = 0; j < 16; ++j) {
284 size_t idx = i + j - 15;
285 if (idx < len) {
286 char c = ((char*)data)[idx];
287 print("%c", c >= 32 && c <= 126 ? c : '.');
288 }
289 }
290 }
291 print_cr("");
292 }
293 }
294 }
295
296 stringStream::stringStream(size_t initial_size) : outputStream() {
297 buffer_length = initial_size;
298 buffer = NEW_RESOURCE_ARRAY(char, buffer_length);
299 buffer_pos = 0;
300 buffer_fixed = false;
301 }
302
303 // useful for output to fixed chunks of memory, such as performance counters
304 stringStream::stringStream(char* fixed_buffer, size_t fixed_buffer_size) : outputStream() {
305 buffer_length = fixed_buffer_size;
306 buffer = fixed_buffer;
307 buffer_pos = 0;
308 buffer_fixed = true;
309 }
310
311 void stringStream::write(const char* s, size_t len) {
312 size_t write_len = len; // number of non-null bytes to write
313 size_t end = buffer_pos + len + 1; // position after write and final '\0'
|