/* * Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// Do not assert this condition if there's already another error reported. #define assert_if_no_error(cond, msg) \
vmassert((cond) || VMError::is_error_reported(), msg)
// Pass the given chars directly to _out. void xmlStream::write(constchar* s, size_t len) { if (!is_open()) return;
out()->write(s, len);
update_position(s, len);
}
// Pass the given chars directly to _out, except that // we watch for special "<&>" chars. // This is suitable for either attribute text or for body text. // We don't fool with "<![CDATA[" quotes, just single-character entities. // This makes it easier for dumb tools to parse the output. void xmlStream::write_text(constchar* s, size_t len) { if (!is_open()) return;
size_t written = 0; // All normally printed material goes inside XML quotes. // This leaves the output free to include markup also. // Scan the string looking for inadvertent "<&>" chars for (size_t i = 0; i < len; i++) { char ch = s[i]; // Escape special chars. constchar* esc = NULL; switch (ch) { // These are important only in attrs, but we do them always: case'\'': esc = "'"; break; case'"': esc = """; break; case'<': esc = "<"; break; case'&': esc = "&"; break; // This is a freebie. case'>': esc = ">"; break;
} if (esc != NULL) { if (written < i) {
out()->write(&s[written], i - written);
written = i;
}
out()->print_raw(esc);
written++;
}
}
// Print the clean remainder. Usually, it is all of s. if (written < len) {
out()->write(&s[written], len - written);
}
}
// ------------------------------------------------------------------ // Outputs XML text, with special characters quoted. void xmlStream::text(constchar* format, ...) {
va_list ap;
va_start(ap, format);
va_text(format, ap);
va_end(ap);
}
#define BUFLEN 2*K /* max size of output of individual print methods */
#ifdef ASSERT /// Debugging goo to make sure element tags nest properly.
// ------------------------------------------------------------------ void xmlStream::see_tag(constchar* tag, bool push) {
assert_if_no_error(!inside_attrs(), "cannot start new element inside attrs"); if (!push) return;
// tag goes up until either null or space: constchar* tag_end = strchr(tag, ' ');
size_t tag_len = (tag_end == NULL) ? strlen(tag) : tag_end - tag;
assert(tag_len > 0, "tag must not be empty"); // push the tag onto the stack, pulling down the pointer char* old_ptr = _element_close_stack_ptr; char* old_low = _element_close_stack_low; char* push_ptr = old_ptr - (tag_len+1); if (push_ptr < old_low) { int old_len = _element_close_stack_high - old_ptr; int new_len = old_len * 2; if (new_len < 100) new_len = 100; char* new_low = NEW_C_HEAP_ARRAY(char, new_len, mtInternal); char* new_high = new_low + new_len; char* new_ptr = new_high - old_len;
memcpy(new_ptr, old_ptr, old_len);
_element_close_stack_high = new_high;
_element_close_stack_low = new_low;
_element_close_stack_ptr = new_ptr;
FREE_C_HEAP_ARRAY(char, old_low);
push_ptr = new_ptr - (tag_len+1);
}
assert(push_ptr >= _element_close_stack_low, "in range");
memcpy(push_ptr, tag, tag_len);
push_ptr[tag_len] = 0;
_element_close_stack_ptr = push_ptr;
_element_depth += 1;
}
// ------------------------------------------------------------------ void xmlStream::pop_tag(constchar* tag) {
assert_if_no_error(!inside_attrs(), "cannot close element inside attrs");
assert(_element_depth > 0, "must be in an element to close");
assert(*tag != 0, "tag must not be empty"); char* cur_tag = _element_close_stack_ptr; bool bad_tag = false; while (*cur_tag != 0 && strcmp(cur_tag, tag) != 0) {
this->print_cr("%s> ", cur_tag);
_element_close_stack_ptr = (cur_tag += strlen(cur_tag) + 1);
_element_depth -= 1;
bad_tag = true;
} if (*cur_tag == 0) {
bad_tag = true;
} else { // Pop the stack, by skipping over the tag and its null.
_element_close_stack_ptr = cur_tag + strlen(cur_tag) + 1;
_element_depth -= 1;
} if (bad_tag && !VMThread::should_terminate() && !VM_Exit::vm_exited() &&
!VMError::is_error_reported())
{
assert(false, "bad tag in log");
}
} #endif
// ------------------------------------------------------------------ // First word in formatted string is element kind, and any subsequent // words must be XML attributes. Outputs "<kind .../>". void xmlStream::elem(constchar* format, ...) {
va_list ap;
va_start(ap, format);
va_elem(format, ap);
va_end(ap);
}
// ------------------------------------------------------------------ // First word in formatted string is element kind, and any subsequent // words must be XML attributes. Outputs "<kind ...", not including "/>". void xmlStream::begin_elem(constchar* format, ...) {
va_list ap;
va_start(ap, format);
va_tag(false, format, ap);
va_end(ap);
}
// ------------------------------------------------------------------ void xmlStream::va_begin_elem(constchar* format, va_list ap) {
va_tag(false, format, ap);
}
// ------------------------------------------------------------------ // Outputs formatted text, followed by "/>". void xmlStream::end_elem(constchar* format, ...) {
va_list ap;
va_start(ap, format);
out()->vprint(format, ap);
va_end(ap);
end_elem();
}
// ------------------------------------------------------------------ // First word in formatted string is element kind, and any subsequent // words must be XML attributes. Outputs "<kind ...>". void xmlStream::head(constchar* format, ...) {
va_list ap;
va_start(ap, format);
va_head(format, ap);
va_end(ap);
}
// ------------------------------------------------------------------ // First word in formatted string is element kind, and any subsequent // words must be XML attributes. Outputs "<kind ...", not including ">". void xmlStream::begin_head(constchar* format, ...) {
va_list ap;
va_start(ap, format);
va_tag(true, format, ap);
va_end(ap);
}
// ------------------------------------------------------------------ void xmlStream::va_begin_head(constchar* format, va_list ap) {
va_tag(true, format, ap);
}
// ------------------------------------------------------------------ // Outputs "<kind_done stamp='D.DD'/> </kind>". // Because done_raw() doesn't need to format strings, it's simpler than // done(), and can be called safely by fatal error handler. void xmlStream::done_raw(constchar* kind) {
print_raw("<");
print_raw(kind);
print_raw("_done stamp='");
out()->stamp();
print_raw_cr("'/>");
print_raw("");
print_raw(kind);
print_raw_cr(">");
}
// If you remove the PRAGMA, this fails to compile with clang-503.0.40.
PRAGMA_DIAG_PUSH
PRAGMA_FORMAT_NONLITERAL_IGNORED // ------------------------------------------------------------------ void xmlStream::va_done(constchar* format, va_list ap) { char buffer[200];
size_t format_len = strlen(format);
guarantee(format_len + 10 < sizeof(buffer), "bigger format buffer"); constchar* kind = format; constchar* kind_end = strchr(kind, ' ');
size_t kind_len; if (kind_end != NULL) {
kind_len = kind_end - kind; int n = os::snprintf(buffer, sizeof(buffer), "%.*s_done", (int)kind_len, kind);
assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
} else {
kind_len = format_len; int n = os::snprintf(buffer, sizeof(buffer), "%s_done%s", kind, kind + kind_len);
assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
} // Output the trailing event with the timestamp.
va_begin_elem(buffer, ap);
stamp();
end_elem(); // Output the tail-tag of the enclosing element.
buffer[kind_len] = 0;
tail(buffer);
}
PRAGMA_DIAG_POP
// Output a timestamp attribute. void xmlStream::stamp() {
assert_if_no_error(inside_attrs(), "stamp must be an attribute");
print_raw(" stamp='");
out()->stamp();
print_raw("'");
}
// ------------------------------------------------------------------ // Output a method attribute, in the form " method='pkg/cls name sig'". // This is used only when there is no ciMethod available. void xmlStream::method(Method* method) {
assert_if_no_error(inside_attrs(), "printing attributes"); if (method == NULL) return;
print_raw(" method='");
method_text(method);
print("' bytes='%d'", method->code_size());
print(" count='%d'", method->invocation_count()); int bec = method->backedge_count(); if (bec != 0) print(" backedge_count='%d'", bec);
print(" iicount='%d'", method->interpreter_invocation_count()); int throwouts = method->interpreter_throwout_count(); if (throwouts != 0) print(" throwouts='%d'", throwouts);
MethodData* mdo = method->method_data(); if (mdo != NULL) {
uint cnt;
cnt = mdo->decompile_count(); if (cnt != 0) print(" decompiles='%d'", cnt); for (uint reason = 0; reason < mdo->trap_reason_limit(); reason++) {
cnt = mdo->trap_count(reason); if (cnt != 0) print(" %s_traps='%d'", Deoptimization::trap_reason_name(reason), cnt);
}
cnt = mdo->overflow_trap_count(); if (cnt != 0) print(" overflow_traps='%d'", cnt);
cnt = mdo->overflow_recompile_count(); if (cnt != 0) print(" overflow_recompiles='%d'", cnt);
}
}
void xmlStream::method_text(Method* method) {
ResourceMark rm;
assert_if_no_error(inside_attrs(), "printing attributes"); if (method == NULL) return;
text()->print("%s", method->method_holder()->external_name());
print_raw(" "); // " " is easier for tools to parse than "::"
method->name()->print_symbol_on(text());
print_raw(" "); // separator
method->signature()->print_symbol_on(text());
}
// ------------------------------------------------------------------ // Output a klass attribute, in the form " klass='pkg/cls'". // This is used only when there is no ciKlass available. void xmlStream::klass(Klass* klass) {
assert_if_no_error(inside_attrs(), "printing attributes"); if (klass == NULL) return;
print_raw(" klass='");
klass_text(klass);
print_raw("'");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.