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