< prev index next >

src/hotspot/share/utilities/xmlstream.cpp

Print this page

 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 "code/nmethod.hpp"
 26 #include "memory/allocation.hpp"
 27 #include "memory/allocation.inline.hpp"
 28 #include "memory/resourceArea.hpp"
 29 #include "oops/methodData.hpp"
 30 #include "oops/method.inline.hpp"
 31 #include "oops/oop.inline.hpp"
 32 #include "runtime/deoptimization.hpp"
 33 #include "runtime/handles.inline.hpp"

 34 #include "runtime/vmOperations.hpp"
 35 #include "runtime/vmThread.hpp"
 36 #include "utilities/vmError.hpp"
 37 #include "utilities/xmlstream.hpp"
 38 









































 39 // Do not assert this condition if there's already another error reported.
 40 #define assert_if_no_error(cond, msg) \
 41   vmassert((cond) || VMError::is_error_reported(), msg)



 42 
 43 void xmlStream::initialize(outputStream* out) {
 44   _out = out;
 45   _last_flush = 0;
 46   _markup_state = BODY;
 47   _text_init._outer_xmlStream = this;
 48   _text = &_text_init;

 49 
 50 #ifdef ASSERT
 51   _element_depth = 0;
 52   int   init_len = 100;
 53   char* init_buf = NEW_C_HEAP_ARRAY(char, init_len, mtInternal);
 54   _element_close_stack_low  = init_buf;
 55   _element_close_stack_high = init_buf + init_len;
 56   _element_close_stack_ptr  = init_buf + init_len - 1;
 57   _element_close_stack_ptr[0] = '\0';
 58 #endif
 59 
 60   // Make sure each log uses the same base for time stamps.
 61   if (is_open()) {
 62     _out->time_stamp().update_to(1);
 63   }
 64 }
 65 
 66 #ifdef ASSERT
 67 xmlStream::~xmlStream() {
 68   FREE_C_HEAP_ARRAY(char, _element_close_stack_low);

111       out()->print_raw(esc);
112       written++;
113     }
114   }
115 
116   // Print the clean remainder.  Usually, it is all of s.
117   if (written < len) {
118     out()->write(&s[written], len - written);
119   }
120 }
121 
122 // ------------------------------------------------------------------
123 // Outputs XML text, with special characters quoted.
124 void xmlStream::text(const char* format, ...) {
125   va_list ap;
126   va_start(ap, format);
127   va_text(format, ap);
128   va_end(ap);
129 }
130 









131 #define BUFLEN 2*K   /* max size of output of individual print methods */
132 
133 // ------------------------------------------------------------------
134 void xmlStream::va_tag(bool push, const char* format, va_list ap) {
135   assert_if_no_error(!inside_attrs(), "cannot print tag inside attrs");
136   char buffer[BUFLEN];
137   size_t len;
138   const char* kind = do_vsnprintf(buffer, BUFLEN, format, ap, false, len);
139   see_tag(kind, push);


140   print_raw("<");
141   write(kind, len);
142   _markup_state = (push ? HEAD : ELEM);
143 }
144 
145 #ifdef ASSERT
146 /// Debugging goo to make sure element tags nest properly.
147 
148 // ------------------------------------------------------------------
149 void xmlStream::see_tag(const char* tag, bool push) {
150   assert_if_no_error(!inside_attrs(), "cannot start new element inside attrs");
151   if (!push)  return;
152 
153   // tag goes up until either null or space:
154   const char* tag_end = strchr(tag, ' ');
155   size_t tag_len = (tag_end == nullptr) ? strlen(tag) : tag_end - tag;
156   assert(tag_len > 0, "tag must not be empty");
157   // push the tag onto the stack, pulling down the pointer
158   char* old_ptr  = _element_close_stack_ptr;
159   char* old_low  = _element_close_stack_low;

297   print_raw(">\n");
298   _markup_state = BODY;
299 }
300 
301 
302 // ------------------------------------------------------------------
303 // Outputs formatted text, followed by ">".
304 void xmlStream::end_head(const char* format, ...) {
305   va_list ap;
306   va_start(ap, format);
307   out()->vprint(format, ap);
308   va_end(ap);
309   end_head();
310 }
311 
312 
313 // ------------------------------------------------------------------
314 // Outputs "</kind>".
315 void xmlStream::tail(const char* kind) {
316   pop_tag(kind);


317   print_raw("</");
318   print_raw(kind);
319   print_raw(">\n");
320 }
321 
322 // ------------------------------------------------------------------
323 // Outputs "<kind_done ... stamp='D.DD'/> </kind>".
324 void xmlStream::done(const char* format, ...) {
325   va_list ap;
326   va_start(ap, format);
327   va_done(format, ap);
328   va_end(ap);
329 }
330 
331 // ------------------------------------------------------------------
332 // Outputs "<kind_done stamp='D.DD'/> </kind>".
333 // Because done_raw() doesn't need to format strings, it's simpler than
334 // done(), and can be called safely by fatal error handler.
335 void xmlStream::done_raw(const char* kind) {
336   print_raw("<");

358     kind_len = kind_end - kind;
359     int n = os::snprintf(buffer, sizeof(buffer), "%.*s_done%s", (int)kind_len, kind, kind + kind_len);
360     assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
361   } else {
362     kind_len = format_len;
363     int n = os::snprintf(buffer, sizeof(buffer), "%s_done", kind);
364     assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
365   }
366   // Output the trailing event with the timestamp.
367   va_begin_elem(buffer, ap);
368   stamp();
369   end_elem();
370   // Output the tail-tag of the enclosing element.
371   buffer[kind_len] = 0;
372   tail(buffer);
373 }
374 PRAGMA_DIAG_POP
375 
376 // Output a timestamp attribute.
377 void xmlStream::stamp() {
378   assert_if_no_error(inside_attrs(), "stamp must be an attribute");
379   print_raw(" stamp='");
380   out()->stamp();
381   print_raw("'");
382 }
383 
384 
385 // ------------------------------------------------------------------
386 // Output a method attribute, in the form " method='pkg/cls name sig'".
387 // This is used only when there is no ciMethod available.
388 void xmlStream::method(Method* method) {
389   assert_if_no_error(inside_attrs(), "printing attributes");
390   if (method == nullptr)  return;
391   print_raw(" method='");






392   method_text(method);
393   print("' bytes='%d'", method->code_size());
394   print(" count='%d'", method->invocation_count());






395   int bec = method->backedge_count();
396   if (bec != 0)  print(" backedge_count='%d'", bec);
397   print(" iicount='%d'", method->interpreter_invocation_count());
398   int throwouts = method->interpreter_throwout_count();
399   if (throwouts != 0)  print(" throwouts='%d'", throwouts);
400   MethodData* mdo = method->method_data();
401   if (mdo != nullptr) {
402     uint cnt;
403     cnt = mdo->decompile_count();
404     if (cnt != 0)  print(" decompiles='%d'", cnt);
405     for (uint reason = 0; reason < mdo->trap_reason_limit(); reason++) {
406       cnt = mdo->trap_count(reason);
407       if (cnt != 0)  print(" %s_traps='%d'", Deoptimization::trap_reason_name(reason), cnt);
408     }
409     cnt = mdo->overflow_trap_count();
410     if (cnt != 0)  print(" overflow_traps='%d'", cnt);
411     cnt = mdo->overflow_recompile_count();
412     if (cnt != 0)  print(" overflow_recompiles='%d'", cnt);
413   }
414 }
415 
416 void xmlStream::method_text(Method* method) {
417   ResourceMark rm;
418   assert_if_no_error(inside_attrs(), "printing attributes");
419   if (method == nullptr)  return;
420   text()->print("%s", method->method_holder()->external_name());
421   print_raw(" ");  // " " is easier for tools to parse than "::"
422   method->name()->print_symbol_on(text());
423   print_raw(" ");  // separator
424   method->signature()->print_symbol_on(text());
425 }
426 
427 
428 // ------------------------------------------------------------------
429 // Output a klass attribute, in the form " klass='pkg/cls'".
430 // This is used only when there is no ciKlass available.
431 void xmlStream::klass(Klass* klass) {
432   assert_if_no_error(inside_attrs(), "printing attributes");
433   if (klass == nullptr) return;
434   print_raw(" klass='");
435   klass_text(klass);
436   print_raw("'");



437 }
438 
439 void xmlStream::klass_text(Klass* klass) {
440   assert_if_no_error(inside_attrs(), "printing attributes");
441   if (klass == nullptr) return;
442   //klass->print_short_name(log->out());
443   klass->name()->print_symbol_on(out());




444 }
445 
446 void xmlStream::name(const Symbol* name) {
447   assert_if_no_error(inside_attrs(), "printing attributes");















448   if (name == nullptr)  return;
449   print_raw(" name='");
450   name_text(name);
451   print_raw("'");
452 }
453 
454 void xmlStream::name_text(const Symbol* name) {
455   assert_if_no_error(inside_attrs(), "printing attributes");








456   if (name == nullptr)  return;
457   //name->print_short_name(text());
458   name->print_symbol_on(text());






















459 }
460 
461 void xmlStream::object(const char* attr, Handle x) {
462   assert_if_no_error(inside_attrs(), "printing attributes");
463   if (x == nullptr)  return;
464   print_raw(" ");
465   print_raw(attr);
466   print_raw("='");
467   object_text(x);
468   print_raw("'");
469 }
470 
471 void xmlStream::object_text(Handle x) {
472   assert_if_no_error(inside_attrs(), "printing attributes");
473   if (x == nullptr)  return;
474   x->print_value_on(text());










475 }
476 
477 
478 void xmlStream::object(const char* attr, Metadata* x) {
479   assert_if_no_error(inside_attrs(), "printing attributes");
480   if (x == nullptr)  return;
481   print_raw(" ");
482   print_raw(attr);
483   print_raw("='");
484   object_text(x);
485   print_raw("'");
486 }
487 
488 void xmlStream::object_text(Metadata* x) {
489   assert_if_no_error(inside_attrs(), "printing attributes");
490   if (x == nullptr)  return;
491   //x->print_value_on(text());
492   if (x->is_method())
493     method_text((Method*)x);
494   else if (x->is_klass())
495     klass_text((Klass*)x);
496   else
497     ShouldNotReachHere(); // Add impl if this is reached.
498 }
499 
500 
501 void xmlStream::flush() {
502   out()->flush();
503   _last_flush = count();
504 }
505 
506 void xmlTextStream::flush() {
507   if (_outer_xmlStream == nullptr)  return;
508   _outer_xmlStream->flush();
509 }

 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 "code/nmethod.hpp"
 26 #include "memory/allocation.hpp"
 27 #include "memory/allocation.inline.hpp"
 28 #include "memory/resourceArea.hpp"
 29 #include "oops/methodData.hpp"
 30 #include "oops/method.inline.hpp"
 31 #include "oops/oop.inline.hpp"
 32 #include "runtime/deoptimization.hpp"
 33 #include "runtime/handles.inline.hpp"
 34 #include "runtime/osThread.hpp"
 35 #include "runtime/vmOperations.hpp"
 36 #include "runtime/vmThread.hpp"
 37 #include "utilities/vmError.hpp"
 38 #include "utilities/xmlstream.hpp"
 39 
 40 // The XML stream is the contents of the LogFile (default hotspot_%p.log).
 41 // It is a superset of whatever might be displayed on the tty.
 42 // You can get to it by calls of the form xtty->...
 43 // Normal calls to tty->... just embed plain text among any markup
 44 // produced via the xtty API.
 45 // The xtty has sub-streams called xtty->text() and xtty->log_long().
 46 // These are ordinary output streams for writing unstructured text.
 47 // The format of this log file is both unstructured and constrained.
 48 //
 49 // Apart from possible race conditions, every line in the log file
 50 // is either an XML element (<tag ...>, or </tag>, or <tag .../>)
 51 // or is unstructured text.
 52 //
 53 // On any given line, if the first character is '<', then the last
 54 // character is '>' and the line consists of a single XML element,
 55 // which uses single quote '\'' to delimit any attribute values.
 56 // (The double-quote character '"' never appears, ever.)
 57 //
 58 // All other lines consist of unstructured text which is completely
 59 // free of the following characters: '<', '>', '&', '\'', '"'.  If
 60 // those characters are written to the tty (or to any other text
 61 // stream underlying the xtty), those characters, and no other
 62 // characters, are written as XML entities: "&lt;", "&gt;", "&amp;",
 63 // "&apos", "&quot".  There is no other use of the character '&'.
 64 //
 65 // The net effect is that you may select a range of tools to process
 66 // the marked-up logs, including XML parsers and simple line-oriented
 67 // Java or Unix tools.  The main concession you have to make to XML
 68 // is to convert the above five XML entities to single ASCII chars,
 69 // as you process attribute strings or unstructured text.
 70 //
 71 // It would be wise to ignore any XML tags that you do not recognize.
 72 // This can be done with grep, if you choose, because the log file
 73 // is line-structured.
 74 //
 75 // The log file collects the output from many contributing threads.
 76 // You should expect that an element of the form <writer thread='NNN'>
 77 // could appear almost anywhere, as the lines interleave.
 78 // It is straightforward to write a script to tease the log file
 79 // into thread-specific substreams.
 80 
 81 // Do not assert this condition if there's already another error reported.
 82 #define assert_if_no_error(cond, msg) \
 83   vmassert((cond) || VMError::is_error_reported(), msg)
 84 bool xmlStream::inside_attrs_or_error() {
 85   return inside_attrs() || VMError::is_error_reported();
 86 }
 87 
 88 void xmlStream::initialize(outputStream* out) {
 89   _out = out;
 90   _last_flush = 0;
 91   _markup_state = BODY;
 92   _text_init._outer_xmlStream = this;
 93   _text = &_text_init;
 94   _log_only = _text;
 95 
 96 #ifdef ASSERT
 97   _element_depth = 0;
 98   int   init_len = 100;
 99   char* init_buf = NEW_C_HEAP_ARRAY(char, init_len, mtInternal);
100   _element_close_stack_low  = init_buf;
101   _element_close_stack_high = init_buf + init_len;
102   _element_close_stack_ptr  = init_buf + init_len - 1;
103   _element_close_stack_ptr[0] = '\0';
104 #endif
105 
106   // Make sure each log uses the same base for time stamps.
107   if (is_open()) {
108     _out->time_stamp().update_to(1);
109   }
110 }
111 
112 #ifdef ASSERT
113 xmlStream::~xmlStream() {
114   FREE_C_HEAP_ARRAY(char, _element_close_stack_low);

157       out()->print_raw(esc);
158       written++;
159     }
160   }
161 
162   // Print the clean remainder.  Usually, it is all of s.
163   if (written < len) {
164     out()->write(&s[written], len - written);
165   }
166 }
167 
168 // ------------------------------------------------------------------
169 // Outputs XML text, with special characters quoted.
170 void xmlStream::text(const char* format, ...) {
171   va_list ap;
172   va_start(ap, format);
173   va_text(format, ap);
174   va_end(ap);
175 }
176 
177 // ------------------------------------------------------------------
178 // Outputs XML attribute, with quotes and special characters quoted.
179 void xmlStream::attr(const char* attr, const char* format, ...) {
180   va_list ap;
181   va_start(ap, format);
182   va_attr(attr, format, ap);
183   va_end(ap);
184 }
185 
186 #define BUFLEN 2*K   /* max size of output of individual print methods */
187 
188 // ------------------------------------------------------------------
189 void xmlStream::va_tag(bool push, const char* format, va_list ap) {
190   assert_if_no_error(!inside_attrs(), "cannot print tag inside attrs");
191   char buffer[BUFLEN];
192   size_t len;
193   const char* kind = do_vsnprintf(buffer, BUFLEN, format, ap, false, len);
194   see_tag(kind, push);
195   // make sure all opening and/or closing tags begin in the first column
196   if (out()->position() > 0)  print_raw("\n");
197   print_raw("<");
198   write(kind, len);
199   _markup_state = (push ? HEAD : ELEM);
200 }
201 
202 #ifdef ASSERT
203 /// Debugging goo to make sure element tags nest properly.
204 
205 // ------------------------------------------------------------------
206 void xmlStream::see_tag(const char* tag, bool push) {
207   assert_if_no_error(!inside_attrs(), "cannot start new element inside attrs");
208   if (!push)  return;
209 
210   // tag goes up until either null or space:
211   const char* tag_end = strchr(tag, ' ');
212   size_t tag_len = (tag_end == nullptr) ? strlen(tag) : tag_end - tag;
213   assert(tag_len > 0, "tag must not be empty");
214   // push the tag onto the stack, pulling down the pointer
215   char* old_ptr  = _element_close_stack_ptr;
216   char* old_low  = _element_close_stack_low;

354   print_raw(">\n");
355   _markup_state = BODY;
356 }
357 
358 
359 // ------------------------------------------------------------------
360 // Outputs formatted text, followed by ">".
361 void xmlStream::end_head(const char* format, ...) {
362   va_list ap;
363   va_start(ap, format);
364   out()->vprint(format, ap);
365   va_end(ap);
366   end_head();
367 }
368 
369 
370 // ------------------------------------------------------------------
371 // Outputs "</kind>".
372 void xmlStream::tail(const char* kind) {
373   pop_tag(kind);
374   // make sure all opening and/or closing tags begin in the first column
375   if (out()->position() > 0)  print_raw("\n");
376   print_raw("</");
377   print_raw(kind);
378   print_raw(">\n");
379 }
380 
381 // ------------------------------------------------------------------
382 // Outputs "<kind_done ... stamp='D.DD'/> </kind>".
383 void xmlStream::done(const char* format, ...) {
384   va_list ap;
385   va_start(ap, format);
386   va_done(format, ap);
387   va_end(ap);
388 }
389 
390 // ------------------------------------------------------------------
391 // Outputs "<kind_done stamp='D.DD'/> </kind>".
392 // Because done_raw() doesn't need to format strings, it's simpler than
393 // done(), and can be called safely by fatal error handler.
394 void xmlStream::done_raw(const char* kind) {
395   print_raw("<");

417     kind_len = kind_end - kind;
418     int n = os::snprintf(buffer, sizeof(buffer), "%.*s_done%s", (int)kind_len, kind, kind + kind_len);
419     assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
420   } else {
421     kind_len = format_len;
422     int n = os::snprintf(buffer, sizeof(buffer), "%s_done", kind);
423     assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
424   }
425   // Output the trailing event with the timestamp.
426   va_begin_elem(buffer, ap);
427   stamp();
428   end_elem();
429   // Output the tail-tag of the enclosing element.
430   buffer[kind_len] = 0;
431   tail(buffer);
432 }
433 PRAGMA_DIAG_POP
434 
435 // Output a timestamp attribute.
436 void xmlStream::stamp() {
437   assert(inside_attrs_or_error(), "stamp must be an attribute");
438   print_raw(" stamp='");
439   out()->stamp();
440   print_raw("'");
441 }
442 
443 
444 // ------------------------------------------------------------------
445 // Output a method attribute, in the form " method='pkg/cls name sig'".
446 // This is used only when there is no ciMethod available.
447 void xmlStream::method(Method* method, const char* pfx) {
448   assert(inside_attrs_or_error(), "printing attributes");
449   if (method == nullptr)  return;
450   if (*pfx) {
451     print(" %smethod='", pfx);
452     method_text(method);
453     print_raw("'");
454     return;
455   }
456   print(" method='");
457   method_text(method);
458   print("' bytes='%d'", method->code_size());
459   print(" count='%d'", method->invocation_count());
460   if (RecordTraining) {
461     // print stuff about this method's compilation history
462     print(" highest_comp_level='%d'", method->highest_comp_level());
463     nmethod* nm = method->code();
464     if (nm != nullptr)  print(" last_compile_id='%d'", nm->compile_id());
465   }
466   int bec = method->backedge_count();
467   if (bec != 0)  print(" backedge_count='%d'", bec);
468   print(" iicount='%d'", method->interpreter_invocation_count());
469   int throwouts = method->interpreter_throwout_count();
470   if (throwouts != 0)  print(" throwouts='%d'", throwouts);
471   MethodData* mdo = method->method_data();
472   if (mdo != nullptr) {
473     uint cnt;
474     cnt = mdo->decompile_count();
475     if (cnt != 0)  print(" decompiles='%d'", cnt);
476     for (uint reason = 0; reason < mdo->trap_reason_limit(); reason++) {
477       cnt = mdo->trap_count(reason);
478       if (cnt != 0)  print(" %s_traps='%d'", Deoptimization::trap_reason_name(reason), cnt);
479     }
480     cnt = mdo->overflow_trap_count();
481     if (cnt != 0)  print(" overflow_traps='%d'", cnt);
482     cnt = mdo->overflow_recompile_count();
483     if (cnt != 0)  print(" overflow_recompiles='%d'", cnt);
484   }
485 }
486 
487 void xmlStream::method_text(Method* method) {
488   ResourceMark rm;
489   assert(inside_attrs_or_error(), "printing attributes");
490   if (method == nullptr)  return;
491   text()->print("%s", method->method_holder()->external_name());
492   print_raw(" ");  // " " is easier for tools to parse than "::"
493   method->name()->print_symbol_on(text());
494   print_raw(" ");  // separator
495   method->signature()->print_symbol_on(text());
496 }
497 
498 
499 // ------------------------------------------------------------------
500 // Output a klass attribute, in the form " klass='pkg/cls'".
501 // This is used only when there is no ciKlass available.
502 void xmlStream::klass(Klass* klass, const char* pfx) {
503   assert(inside_attrs_or_error(), "printing attributes");
504   if (klass == nullptr) return;
505   print(" %sklass='", pfx);
506   klass_text(klass);
507   print_raw("'");
508   if (klass->class_loader() != nullptr) {
509     loader(klass->class_loader(), pfx);
510   }
511 }
512 
513 void xmlStream::klass_text(Klass* klass) {
514   assert(inside_attrs_or_error(), "printing attributes");
515   if (klass == nullptr) return;
516   //klass->print_short_name(log->out());
517   klass->name()->print_symbol_on(out());
518   if (klass->is_hidden()) {
519     out()->print(" //hidden");
520     // FIXME:  maybe hash the contents of its classfile
521   }
522 }
523 
524 void xmlStream::loader(oop cl, const char* pfx) {
525   assert(inside_attrs_or_error(), "printing attributes");
526   if (cl == nullptr) return;
527   print(" %sloader='", pfx);
528   loader_text(cl);
529   print_raw("'");
530 }
531 
532 void xmlStream::loader_text(oop cl) {
533   assert(inside_attrs_or_error(), "printing attributes");
534   if (cl == nullptr) return;
535   oop id = java_lang_ClassLoader::nameAndId(cl);
536   if (id != nullptr)  string_text(id);
537 }
538 
539 void xmlStream::name(const Symbol* name, const char* pfx) {
540   assert(inside_attrs_or_error(), "printing attributes");
541   if (name == nullptr)  return;
542   print(" %sname='", pfx);
543   symbol_text(name);
544   print_raw("'");
545 }
546 
547 void xmlStream::signature(const Symbol* sig, const char* pfx) {
548   assert(inside_attrs_or_error(), "printing attributes");
549   if (sig == nullptr)  return;
550   print(" %ssignature='", pfx);
551   symbol_text(sig);
552   print_raw("'");
553 }
554 
555 void xmlStream::symbol_text(const Symbol* name) {
556   assert(inside_attrs_or_error(), "printing attributes");
557   if (name == nullptr)  return;
558   //name->print_short_name(text());
559   //name->print_symbol_on(text());  // this has odd escapes in it (\\x%04x)
560   const char* base = (const char*) name->base();
561   int len = name->utf8_length();
562   log_only()->write(base, len);
563 }
564 
565 void xmlStream::string_text(oop str) {
566   assert(inside_attrs_or_error(), "printing attributes");
567   if (str == nullptr)  return;
568   if (!java_lang_String::is_instance(str)) {
569     print("*** not a string*** ");
570     str->print_value_on(log_only());
571     return;
572   }
573   ResourceMark rm;
574   log_only()->print_raw(java_lang_String::as_utf8_string(str));
575 }
576 
577 void xmlStream::thread(Thread* t, const char* pfx) {
578   assert(inside_attrs_or_error(), "printing attributes");
579   intx tid = t == nullptr ? os::current_thread_id() : t->osthread()->thread_id();
580   guarantee(tid == (t == nullptr ? Thread::current() : t)->osthread()->thread_id(), "");
581   print(" %sthread=%zd", pfx, tid);
582 }
583 
584 void xmlStream::object(const char* attr, Handle x) {
585   assert(inside_attrs_or_error(), "printing attributes");
586   if (x == nullptr)  return;
587   print_raw(" ");
588   print_raw(attr);
589   print_raw("='");
590   object_text(x);
591   print_raw("'");
592 }
593 
594 void xmlStream::object_text(Handle x) {
595   assert(inside_attrs_or_error(), "printing attributes");
596   if (x.is_null())  return;
597   if (java_lang_ClassLoader::is_instance(x())) {
598     print_raw("loader:");
599     loader_text(x());
600     return;
601   }
602   if (java_lang_String::is_instance(x())) {
603     print_raw("string:");
604     string_text(x());
605     return;
606   }
607   x->print_value_on(log_only());
608 }
609 
610 
611 void xmlStream::object(const char* attr, Metadata* x) {
612   assert(inside_attrs_or_error(), "printing attributes");
613   if (x == nullptr)  return;
614   print_raw(" ");
615   print_raw(attr);
616   print_raw("='");
617   object_text(x);
618   print_raw("'");
619 }
620 
621 void xmlStream::object_text(Metadata* x) {
622   assert(inside_attrs_or_error(), "printing attributes");
623   if (x == nullptr)  return;
624   //x->print_value_on(text());
625   if (x->is_method())
626     method_text((Method*)x);
627   else if (x->is_klass())
628     klass_text((Klass*)x);
629   else
630     ShouldNotReachHere(); // Add impl if this is reached.
631 }
632 
633 
634 void xmlStream::flush() {
635   out()->flush();
636   _last_flush = count();
637 }
638 
639 void xmlTextStream::flush() {
640   if (_outer_xmlStream == nullptr)  return;
641   _outer_xmlStream->flush();
642 }
< prev index next >