src/share/vm/compiler/compileLog.cpp

Wed, 08 May 2013 15:08:01 -0700

author
kvn
date
Wed, 08 May 2013 15:08:01 -0700
changeset 5110
6f3fd5150b67
parent 4889
cc32ccaaf47f
child 5226
813f26e34135
permissions
-rw-r--r--

6934604: enable parts of EliminateAutoBox by default
Summary: Resurrected autobox elimination code and enabled part of it by default.
Reviewed-by: roland, twisti

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "ci/ciMethod.hpp"
stefank@2314 27 #include "compiler/compileLog.hpp"
stefank@2314 28 #include "memory/allocation.inline.hpp"
coleenp@4037 29 #include "oops/method.hpp"
stefank@2314 30 #include "runtime/mutexLocker.hpp"
stefank@2314 31 #include "runtime/os.hpp"
duke@435 32
duke@435 33 CompileLog* CompileLog::_first = NULL;
duke@435 34
duke@435 35 // ------------------------------------------------------------------
duke@435 36 // CompileLog::CompileLog
duke@435 37 CompileLog::CompileLog(const char* file, FILE* fp, intx thread_id)
duke@435 38 : _context(_context_buffer, sizeof(_context_buffer))
duke@435 39 {
zgu@3900 40 initialize(new(ResourceObj::C_HEAP, mtCompiler) fileStream(fp));
duke@435 41 _file = file;
duke@435 42 _file_end = 0;
duke@435 43 _thread_id = thread_id;
duke@435 44
duke@435 45 _identities_limit = 0;
duke@435 46 _identities_capacity = 400;
zgu@3900 47 _identities = NEW_C_HEAP_ARRAY(char, _identities_capacity, mtCompiler);
duke@435 48
duke@435 49 // link into the global list
duke@435 50 { MutexLocker locker(CompileTaskAlloc_lock);
duke@435 51 _next = _first;
duke@435 52 _first = this;
duke@435 53 }
duke@435 54 }
duke@435 55
duke@435 56 CompileLog::~CompileLog() {
duke@435 57 delete _out;
duke@435 58 _out = NULL;
zgu@3900 59 FREE_C_HEAP_ARRAY(char, _identities, mtCompiler);
duke@435 60 }
duke@435 61
duke@435 62
duke@435 63 // see_tag, pop_tag: Override the default do-nothing methods on xmlStream.
duke@435 64 // These methods provide a hook for managing the the extra context markup.
duke@435 65 void CompileLog::see_tag(const char* tag, bool push) {
duke@435 66 if (_context.size() > 0 && _out != NULL) {
duke@435 67 _out->write(_context.base(), _context.size());
duke@435 68 _context.reset();
duke@435 69 }
duke@435 70 xmlStream::see_tag(tag, push);
duke@435 71 }
duke@435 72 void CompileLog::pop_tag(const char* tag) {
duke@435 73 _context.reset(); // toss any context info.
duke@435 74 xmlStream::pop_tag(tag);
duke@435 75 }
duke@435 76
duke@435 77
duke@435 78 // ------------------------------------------------------------------
duke@435 79 // CompileLog::identify
coleenp@4037 80 int CompileLog::identify(ciBaseObject* obj) {
duke@435 81 if (obj == NULL) return 0;
duke@435 82 int id = obj->ident();
duke@435 83 if (id < 0) return id;
duke@435 84 // If it has already been identified, just return the id.
duke@435 85 if (id < _identities_limit && _identities[id] != 0) return id;
duke@435 86 // Lengthen the array, if necessary.
duke@435 87 if (id >= _identities_capacity) {
duke@435 88 int new_cap = _identities_capacity * 2;
duke@435 89 if (new_cap <= id) new_cap = id + 100;
zgu@3900 90 _identities = REALLOC_C_HEAP_ARRAY(char, _identities, new_cap, mtCompiler);
duke@435 91 _identities_capacity = new_cap;
duke@435 92 }
duke@435 93 while (id >= _identities_limit) {
duke@435 94 _identities[_identities_limit++] = 0;
duke@435 95 }
duke@435 96 assert(id < _identities_limit, "oob");
duke@435 97 // Mark this id as processed.
duke@435 98 // (Be sure to do this before any recursive calls to identify.)
duke@435 99 _identities[id] = 1; // mark
duke@435 100
duke@435 101 // Now, print the object's identity once, in detail.
coleenp@4037 102 if (obj->is_metadata()) {
coleenp@4037 103 ciMetadata* mobj = obj->as_metadata();
coleenp@4037 104 if (mobj->is_klass()) {
coleenp@4037 105 ciKlass* klass = mobj->as_klass();
twisti@4111 106 begin_elem("klass id='%d'", id);
twisti@4111 107 name(klass->name());
twisti@4111 108 if (!klass->is_loaded()) {
twisti@4111 109 print(" unloaded='1'");
twisti@4111 110 } else {
twisti@4111 111 print(" flags='%d'", klass->modifier_flags());
twisti@4111 112 }
twisti@4111 113 end_elem();
coleenp@4037 114 } else if (mobj->is_method()) {
coleenp@4037 115 ciMethod* method = mobj->as_method();
twisti@4111 116 ciSignature* sig = method->signature();
twisti@4111 117 // Pre-identify items that we will need!
twisti@4111 118 identify(sig->return_type());
duke@435 119 for (int i = 0; i < sig->count(); i++) {
twisti@4111 120 identify(sig->type_at(i));
duke@435 121 }
twisti@4111 122 begin_elem("method id='%d' holder='%d'",
twisti@4111 123 id, identify(method->holder()));
twisti@4111 124 name(method->name());
twisti@4111 125 print(" return='%d'", identify(sig->return_type()));
twisti@4111 126 if (sig->count() > 0) {
twisti@4111 127 print(" arguments='");
twisti@4111 128 for (int i = 0; i < sig->count(); i++) {
twisti@4111 129 print((i == 0) ? "%d" : " %d", identify(sig->type_at(i)));
twisti@4111 130 }
twisti@4111 131 print("'");
twisti@4111 132 }
twisti@4111 133 if (!method->is_loaded()) {
twisti@4111 134 print(" unloaded='1'");
twisti@4111 135 } else {
twisti@4111 136 print(" flags='%d'", (jchar) method->flags().as_int());
twisti@4111 137 // output a few metrics
twisti@4111 138 print(" bytes='%d'", method->code_size());
twisti@4111 139 method->log_nmethod_identity(this);
twisti@4111 140 //print(" count='%d'", method->invocation_count());
twisti@4111 141 //int bec = method->backedge_count();
twisti@4111 142 //if (bec != 0) print(" backedge_count='%d'", bec);
twisti@4111 143 print(" iicount='%d'", method->interpreter_invocation_count());
twisti@4111 144 }
twisti@4111 145 end_elem();
coleenp@4037 146 } else if (mobj->is_type()) {
coleenp@4037 147 BasicType type = mobj->as_type()->basic_type();
coleenp@4037 148 elem("type id='%d' name='%s'", id, type2name(type));
coleenp@4037 149 } else {
coleenp@4037 150 // Should not happen.
coleenp@4037 151 elem("unknown id='%d'", id);
coleenp@4037 152 ShouldNotReachHere();
coleenp@4037 153 }
duke@435 154 } else if (obj->is_symbol()) {
duke@435 155 begin_elem("symbol id='%d'", id);
duke@435 156 name(obj->as_symbol());
duke@435 157 end_elem();
duke@435 158 } else {
duke@435 159 // Should not happen.
duke@435 160 elem("unknown id='%d'", id);
duke@435 161 }
duke@435 162 return id;
duke@435 163 }
duke@435 164
duke@435 165 void CompileLog::name(ciSymbol* name) {
duke@435 166 if (name == NULL) return;
duke@435 167 print(" name='");
duke@435 168 name->print_symbol_on(text()); // handles quoting conventions
duke@435 169 print("'");
duke@435 170 }
duke@435 171
duke@435 172
duke@435 173 // ------------------------------------------------------------------
duke@435 174 // CompileLog::clear_identities
duke@435 175 // Forget which identities have been printed.
duke@435 176 void CompileLog::clear_identities() {
duke@435 177 _identities_limit = 0;
duke@435 178 }
duke@435 179
duke@435 180 // ------------------------------------------------------------------
duke@435 181 // CompileLog::finish_log_on_error
duke@435 182 //
duke@435 183 // Note: This function is called after fatal error, avoid unnecessary memory
duke@435 184 // or stack allocation, use only async-safe functions. It's possible JVM is
duke@435 185 // only partially initialized.
duke@435 186 void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen) {
duke@435 187 static bool called_exit = false;
duke@435 188 if (called_exit) return;
duke@435 189 called_exit = true;
duke@435 190
duke@435 191 for (CompileLog* log = _first; log != NULL; log = log->_next) {
duke@435 192 log->flush();
duke@435 193 const char* partial_file = log->file();
duke@435 194 int partial_fd = open(partial_file, O_RDONLY);
duke@435 195 if (partial_fd != -1) {
duke@435 196 // print/print_cr may need to allocate large stack buffer to format
duke@435 197 // strings, here we use snprintf() and print_raw() instead.
duke@435 198 file->print_raw("<compilation_log thread='");
duke@435 199 jio_snprintf(buf, buflen, UINTX_FORMAT, log->thread_id());
duke@435 200 file->print_raw(buf);
duke@435 201 file->print_raw_cr("'>");
duke@435 202
duke@435 203 size_t nr; // number read into buf from partial log
duke@435 204 // Copy data up to the end of the last <event> element:
duke@435 205 julong to_read = log->_file_end;
duke@435 206 while (to_read > 0) {
duke@435 207 if (to_read < (julong)buflen)
duke@435 208 nr = (size_t)to_read;
duke@435 209 else nr = buflen;
duke@435 210 nr = read(partial_fd, buf, (int)nr);
duke@435 211 if (nr <= 0) break;
duke@435 212 to_read -= (julong)nr;
duke@435 213 file->write(buf, nr);
duke@435 214 }
duke@435 215
duke@435 216 // Copy any remaining data inside a quote:
duke@435 217 bool saw_slop = false;
duke@435 218 int end_cdata = 0; // state machine [0..2] watching for too many "]]"
duke@435 219 while ((nr = read(partial_fd, buf, buflen)) > 0) {
duke@435 220 if (!saw_slop) {
duke@435 221 file->print_raw_cr("<fragment>");
duke@435 222 file->print_raw_cr("<![CDATA[");
duke@435 223 saw_slop = true;
duke@435 224 }
duke@435 225 // The rest of this loop amounts to a simple copy operation:
duke@435 226 // { file->write(buf, nr); }
duke@435 227 // However, it must sometimes output the buffer in parts,
duke@435 228 // in case there is a CDATA quote embedded in the fragment.
duke@435 229 const char* bufp; // pointer into buf
duke@435 230 size_t nw; // number written in each pass of the following loop:
duke@435 231 for (bufp = buf; nr > 0; nr -= nw, bufp += nw) {
duke@435 232 // Write up to any problematic CDATA delimiter (usually all of nr).
duke@435 233 for (nw = 0; nw < nr; nw++) {
duke@435 234 // First, scan ahead into the buf, checking the state machine.
duke@435 235 switch (bufp[nw]) {
duke@435 236 case ']':
duke@435 237 if (end_cdata < 2) end_cdata += 1; // saturating counter
duke@435 238 continue; // keep scanning
duke@435 239 case '>':
duke@435 240 if (end_cdata == 2) break; // found CDATA delimiter!
duke@435 241 // else fall through:
duke@435 242 default:
duke@435 243 end_cdata = 0;
duke@435 244 continue; // keep scanning
duke@435 245 }
duke@435 246 // If we get here, nw is pointing at a bad '>'.
duke@435 247 // It is very rare for this to happen.
duke@435 248 // However, this code has been tested by introducing
duke@435 249 // CDATA sequences into the compilation log.
duke@435 250 break;
duke@435 251 }
duke@435 252 // Now nw is the number of characters to write, usually == nr.
duke@435 253 file->write(bufp, nw);
duke@435 254 if (nw < nr) {
duke@435 255 // We are about to go around the loop again.
duke@435 256 // But first, disrupt the ]]> by closing and reopening the quote.
duke@435 257 file->print_raw("]]><![CDATA[");
duke@435 258 end_cdata = 0; // reset state machine
duke@435 259 }
duke@435 260 }
duke@435 261 }
duke@435 262 if (saw_slop) {
duke@435 263 file->print_raw_cr("]]>");
duke@435 264 file->print_raw_cr("</fragment>");
duke@435 265 }
duke@435 266 file->print_raw_cr("</compilation_log>");
duke@435 267 close(partial_fd);
duke@435 268 unlink(partial_file);
duke@435 269 }
duke@435 270 }
duke@435 271 }
duke@435 272
duke@435 273 // ------------------------------------------------------------------
duke@435 274 // CompileLog::finish_log
duke@435 275 //
duke@435 276 // Called during normal shutdown. For now, any clean-up needed in normal
duke@435 277 // shutdown is also needed in VM abort, so is covered by finish_log_on_error().
duke@435 278 // Just allocate a buffer and call finish_log_on_error().
duke@435 279 void CompileLog::finish_log(outputStream* file) {
duke@435 280 char buf[4 * K];
duke@435 281 finish_log_on_error(file, buf, sizeof(buf));
duke@435 282 }
vlivanov@4154 283
vlivanov@4154 284 // ------------------------------------------------------------------
vlivanov@4154 285 // CompileLog::inline_success
vlivanov@4154 286 //
vlivanov@4154 287 // Print about successful method inlining.
vlivanov@4154 288 void CompileLog::inline_success(const char* reason) {
vlivanov@4154 289 begin_elem("inline_success reason='");
vlivanov@4154 290 text(reason);
vlivanov@4154 291 end_elem("'");
vlivanov@4154 292 }
vlivanov@4154 293
vlivanov@4154 294 // ------------------------------------------------------------------
vlivanov@4154 295 // CompileLog::inline_fail
vlivanov@4154 296 //
vlivanov@4154 297 // Print about failed method inlining.
vlivanov@4154 298 void CompileLog::inline_fail(const char* reason) {
vlivanov@4154 299 begin_elem("inline_fail reason='");
vlivanov@4154 300 text(reason);
vlivanov@4154 301 end_elem("'");
vlivanov@4154 302 }
vlivanov@4154 303
vlivanov@4154 304 // ------------------------------------------------------------------
vlivanov@4154 305 // CompileLog::set_context
vlivanov@4154 306 //
vlivanov@4154 307 // Set XML tag as an optional marker - it is printed only if
vlivanov@4154 308 // there are other entries after until it is reset.
vlivanov@4154 309 void CompileLog::set_context(const char* format, ...) {
vlivanov@4154 310 va_list ap;
vlivanov@4154 311 va_start(ap, format);
vlivanov@4154 312 clear_context();
vlivanov@4154 313 _context.print("<");
vlivanov@4154 314 _context.vprint(format, ap);
vlivanov@4154 315 _context.print_cr("/>");
vlivanov@4154 316 va_end(ap);
vlivanov@4154 317 }
vlivanov@4154 318
vlivanov@4154 319 // ------------------------------------------------------------------
vlivanov@4154 320 // CompileLog::code_cache_state
vlivanov@4154 321 //
vlivanov@4154 322 // Print code cache state.
vlivanov@4154 323 void CompileLog::code_cache_state() {
vlivanov@4154 324 begin_elem("code_cache");
vlivanov@4154 325 CodeCache::log_state(this);
vlivanov@4154 326 end_elem("");
vlivanov@4154 327 }

mercurial