hotspot/src/share/vm/runtime/sweeper.cpp
author twisti
Thu, 08 Apr 2010 10:55:40 +0200
changeset 5252 58f23871a5b6
parent 4750 71fd601907dc
child 5533 e8d9ff82ec62
permissions -rw-r--r--
6941529: SharedRuntime::raw_exception_handler_for_return_address must reset thread MethodHandle flag Summary: During testing a bug was hit when an exception returned to the interpreter and the SP was wrong. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
3795
6227ff014cfe 6884624: Update copyright year
xdono
parents: 3696
diff changeset
     2
 * Copyright 1997-2009 Sun Microsystems, Inc.  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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_sweeper.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
long      NMethodSweeper::_traversals = 0;   // No. of stack traversals performed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
CodeBlob* NMethodSweeper::_current = NULL;   // Current nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
int       NMethodSweeper::_seen = 0 ;        // No. of blobs we have currently processed in current pass of CodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
int       NMethodSweeper::_invocations = 0;  // No. of invocations left until we are completed with this pass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
jint      NMethodSweeper::_locked_seen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
jint      NMethodSweeper::_not_entrant_seen_on_stack = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
bool      NMethodSweeper::_rescan = false;
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
    36
bool      NMethodSweeper::_was_full = false;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
    37
jint      NMethodSweeper::_advise_to_sweep = 0;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
    38
jlong     NMethodSweeper::_last_was_full = 0;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
    39
uint      NMethodSweeper::_highest_marked = 0;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
    40
long      NMethodSweeper::_was_full_traversal = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    42
class MarkActivationClosure: public CodeBlobClosure {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    43
public:
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    44
  virtual void do_code_blob(CodeBlob* cb) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    45
    // If we see an activation belonging to a non_entrant nmethod, we mark it.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    46
    if (cb->is_nmethod() && ((nmethod*)cb)->is_not_entrant()) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    47
      ((nmethod*)cb)->mark_as_seen_on_stack();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    48
    }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    49
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    50
};
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    51
static MarkActivationClosure mark_activation_closure;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    52
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
void NMethodSweeper::sweep() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  if (!MethodFlushing) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // No need to synchronize access, since this is always executed at a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // safepoint.  If we aren't in the middle of scan and a rescan
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // hasn't been requested then just return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (_current == NULL && !_rescan) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Make sure CompiledIC_lock in unlocked, since we might update some
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // inline caches. If it is, we just bail-out and try later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  if (CompiledIC_lock->is_locked() || Patching_lock->is_locked()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Check for restart
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert(CodeCache::find_blob_unsafe(_current) == _current, "Sweeper nmethod cached state invalid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  if (_current == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    _seen        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    _invocations = NmethodSweepFraction;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    _current     = CodeCache::first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _traversals  += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    if (PrintMethodFlushing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      tty->print_cr("### Sweep: stack traversal %d", _traversals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    }
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
    76
    Threads::nmethods_do(&mark_activation_closure);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    // reset the flags since we started a scan from the beginning.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    _rescan = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    _locked_seen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    _not_entrant_seen_on_stack = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  if (PrintMethodFlushing && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    tty->print_cr("### Sweep at %d out of %d. Invocations left: %d", _seen, CodeCache::nof_blobs(), _invocations);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // We want to visit all nmethods after NmethodSweepFraction invocations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // If invocation is 1 we do the rest
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  int todo = CodeCache::nof_blobs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  if (_invocations != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    todo = (CodeCache::nof_blobs() - _seen) / _invocations;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    _invocations--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  for(int i = 0; i < todo && _current != NULL; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    CodeBlob* next = CodeCache::next(_current); // Read next before we potentially delete current
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    if (_current->is_nmethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      process_nmethod((nmethod *)_current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    _seen++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    _current = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Because we could stop on a codeBlob other than an nmethod we skip forward
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // to the next nmethod (if any). codeBlobs other than nmethods can be freed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // async to us and make _current invalid while we sleep.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  while (_current != NULL && !_current->is_nmethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    _current = CodeCache::next(_current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  if (_current == NULL && !_rescan && (_locked_seen || _not_entrant_seen_on_stack)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // we've completed a scan without making progress but there were
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // nmethods we were unable to process either because they were
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // locked or were still on stack.  We don't have to aggresively
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    // clean them up so just stop scanning.  We could scan once more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    // but that complicates the control logic and it's unlikely to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    // matter much.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    if (PrintMethodFlushing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      tty->print_cr("### Couldn't make progress on some nmethods so stopping sweep");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   122
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   123
  if (UseCodeCacheFlushing) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   124
    if (!CodeCache::needs_flushing()) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   125
      // In a safepoint, no race with setters
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   126
      _advise_to_sweep = 0;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   127
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   128
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   129
    if (was_full()) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   130
      // There was some progress so attempt to restart the compiler
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   131
      jlong now           = os::javaTimeMillis();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   132
      jlong max_interval  = (jlong)MinCodeCacheFlushingInterval * (jlong)1000;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   133
      jlong curr_interval = now - _last_was_full;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   134
      if ((!CodeCache::needs_flushing()) && (curr_interval > max_interval)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   135
        CompileBroker::set_should_compile_new_jobs(CompileBroker::run_compilation);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   136
        set_was_full(false);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   137
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   138
        // Update the _last_was_full time so we can tell how fast the
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   139
        // code cache is filling up
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   140
        _last_was_full = os::javaTimeMillis();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   141
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   142
        if (PrintMethodFlushing) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   143
          tty->print_cr("### sweeper: Live blobs:" UINT32_FORMAT "/Free code cache:" SIZE_FORMAT " bytes, restarting compiler",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   144
            CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   145
        }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   146
        if (LogCompilation && (xtty != NULL)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   147
          ttyLocker ttyl;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   148
          xtty->begin_elem("restart_compiler live_blobs='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   149
                           CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   150
          xtty->stamp();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   151
          xtty->end_elem();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   152
        }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   153
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   154
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   155
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
void NMethodSweeper::process_nmethod(nmethod *nm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // Skip methods that are currently referenced by the VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  if (nm->is_locked_by_vm()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    // But still remember to clean-up inline caches for alive nmethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if (nm->is_alive()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      // Clean-up all inline caches that points to zombie/non-reentrant methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      nm->cleanup_inline_caches();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      _locked_seen++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  if (nm->is_zombie()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // If it is first time, we see nmethod then we mark it. Otherwise,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    // we reclame it. When we have seen a zombie method twice, we know that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    // there are no inline caches that referes to it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if (nm->is_marked_for_reclamation()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      assert(!nm->is_locked_by_vm(), "must not flush locked nmethods");
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   178
      if (PrintMethodFlushing && Verbose) {
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   179
        tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (marked for reclamation) being flushed", nm->compile_id(), nm);
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   180
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      nm->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    } else {
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   183
      if (PrintMethodFlushing && Verbose) {
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   184
        tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (zombie) being marked for reclamation", nm->compile_id(), nm);
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   185
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      nm->mark_for_reclamation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      _rescan = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  } else if (nm->is_not_entrant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    // If there is no current activations of this method on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    // stack we can safely convert it to a zombie method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    if (nm->can_not_entrant_be_converted()) {
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   193
      if (PrintMethodFlushing && Verbose) {
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   194
        tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (not entrant) being made zombie", nm->compile_id(), nm);
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   195
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      nm->make_zombie();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      _rescan = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      // Still alive, clean up its inline caches
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      nm->cleanup_inline_caches();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      // we coudn't transition this nmethod so don't immediately
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      // request a rescan.  If this method stays on the stack for a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      // long time we don't want to keep rescanning at every safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      _not_entrant_seen_on_stack++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  } else if (nm->is_unloaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    // Unloaded code, just make it a zombie
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   208
    if (PrintMethodFlushing && Verbose)
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   209
      tty->print_cr("### Nmethod %3d/" PTR_FORMAT " (unloaded) being made zombie", nm->compile_id(), nm);
3696
9e5d9b5e1049 4957990: Perm heap bloat in JVM
ysr
parents: 1
diff changeset
   210
    if (nm->is_osr_method()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      // No inline caches will ever point to osr methods, so we can just remove it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      nm->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      nm->make_zombie();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      _rescan = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    assert(nm->is_alive(), "should be alive");
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   219
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   220
    if (UseCodeCacheFlushing) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   221
      if ((nm->method()->code() != nm) && !(nm->is_locked_by_vm()) && !(nm->is_osr_method()) &&
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   222
          (_traversals > _was_full_traversal+2) && (((uint)nm->compile_id()) < _highest_marked) &&
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   223
          CodeCache::needs_flushing()) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   224
        // This method has not been called since the forced cleanup happened
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   225
        nm->make_not_entrant();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   226
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   227
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   228
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    // Clean-up all inline caches that points to zombie/non-reentrant methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    nm->cleanup_inline_caches();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
}
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   233
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   234
// Code cache unloading: when compilers notice the code cache is getting full,
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   235
// they will call a vm op that comes here. This code attempts to speculatively
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   236
// unload the oldest half of the nmethods (based on the compile job id) by
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   237
// saving the old code in a list in the CodeCache. Then
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   238
// execution resumes. If a method so marked is not called by the second
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   239
// safepoint from the current one, the nmethod will be marked non-entrant and
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   240
// got rid of by normal sweeping. If the method is called, the methodOop's
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   241
// _code field is restored and the methodOop/nmethod
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   242
// go back to their normal state.
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   243
void NMethodSweeper::handle_full_code_cache(bool is_full) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   244
  // Only the first one to notice can advise us to start early cleaning
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   245
  if (!is_full){
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   246
    jint old = Atomic::cmpxchg( 1, &_advise_to_sweep, 0 );
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   247
    if (old != 0) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   248
      return;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   249
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   250
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   251
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   252
  if (is_full) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   253
    // Since code cache is full, immediately stop new compiles
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   254
    bool did_set = CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   255
    if (!did_set) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   256
      // only the first to notice can start the cleaning,
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   257
      // others will go back and block
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   258
      return;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   259
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   260
    set_was_full(true);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   261
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   262
    // If we run out within MinCodeCacheFlushingInterval of the last unload time, give up
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   263
    jlong now = os::javaTimeMillis();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   264
    jlong max_interval = (jlong)MinCodeCacheFlushingInterval * (jlong)1000;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   265
    jlong curr_interval = now - _last_was_full;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   266
    if (curr_interval < max_interval) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   267
      _rescan = true;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   268
      if (PrintMethodFlushing) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   269
        tty->print_cr("### handle full too often, turning off compiler");
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   270
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   271
      if (LogCompilation && (xtty != NULL)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   272
        ttyLocker ttyl;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   273
        xtty->begin_elem("disable_compiler flushing_interval='" UINT64_FORMAT "' live_blobs='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   274
                         curr_interval/1000, CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   275
        xtty->stamp();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   276
        xtty->end_elem();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   277
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   278
      return;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   279
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   280
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   281
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   282
  VM_HandleFullCodeCache op(is_full);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   283
  VMThread::execute(&op);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   284
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   285
  // rescan again as soon as possible
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   286
  _rescan = true;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   287
}
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   288
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   289
void NMethodSweeper::speculative_disconnect_nmethods(bool is_full) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   290
  // If there was a race in detecting full code cache, only run
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   291
  // one vm op for it or keep the compiler shut off
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   292
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   293
  debug_only(jlong start = os::javaTimeMillis();)
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   294
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   295
  if ((!was_full()) && (is_full)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   296
    if (!CodeCache::needs_flushing()) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   297
      if (PrintMethodFlushing) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   298
        tty->print_cr("### sweeper: Live blobs:" UINT32_FORMAT "/Free code cache:" SIZE_FORMAT " bytes, restarting compiler",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   299
          CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   300
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   301
      if (LogCompilation && (xtty != NULL)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   302
        ttyLocker ttyl;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   303
        xtty->begin_elem("restart_compiler live_blobs='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   304
                         CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   305
        xtty->stamp();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   306
        xtty->end_elem();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   307
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   308
      CompileBroker::set_should_compile_new_jobs(CompileBroker::run_compilation);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   309
      return;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   310
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   311
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   312
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   313
  // Traverse the code cache trying to dump the oldest nmethods
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   314
  uint curr_max_comp_id = CompileBroker::get_compilation_id();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   315
  uint flush_target = ((curr_max_comp_id - _highest_marked) >> 1) + _highest_marked;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   316
  if (PrintMethodFlushing && Verbose) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   317
    tty->print_cr("### Cleaning code cache: Live blobs:" UINT32_FORMAT "/Free code cache:" SIZE_FORMAT " bytes",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   318
        CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   319
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   320
  if (LogCompilation && (xtty != NULL)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   321
    ttyLocker ttyl;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   322
    xtty->begin_elem("start_cleaning_code_cache live_blobs='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   323
                      CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   324
    xtty->stamp();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   325
    xtty->end_elem();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   326
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   327
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   328
  nmethod* nm = CodeCache::alive_nmethod(CodeCache::first());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   329
  jint disconnected = 0;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   330
  jint made_not_entrant  = 0;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   331
  while ((nm != NULL)){
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   332
    uint curr_comp_id = nm->compile_id();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   333
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   334
    // OSR methods cannot be flushed like this. Also, don't flush native methods
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   335
    // since they are part of the JDK in most cases
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   336
    if (nm->is_in_use() && (!nm->is_osr_method()) && (!nm->is_locked_by_vm()) &&
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   337
        (!nm->is_native_method()) && ((curr_comp_id < flush_target))) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   338
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   339
      if ((nm->method()->code() == nm)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   340
        // This method has not been previously considered for
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   341
        // unloading or it was restored already
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   342
        CodeCache::speculatively_disconnect(nm);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   343
        disconnected++;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   344
      } else if (nm->is_speculatively_disconnected()) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   345
        // This method was previously considered for preemptive unloading and was not called since then
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   346
        nm->method()->invocation_counter()->decay();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   347
        nm->method()->backedge_counter()->decay();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   348
        nm->make_not_entrant();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   349
        made_not_entrant++;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   350
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   351
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   352
      if (curr_comp_id > _highest_marked) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   353
        _highest_marked = curr_comp_id;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   354
      }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   355
    }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   356
    nm = CodeCache::alive_nmethod(CodeCache::next(nm));
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   357
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   358
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   359
  if (LogCompilation && (xtty != NULL)) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   360
    ttyLocker ttyl;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   361
    xtty->begin_elem("stop_cleaning_code_cache disconnected='" UINT32_FORMAT "' made_not_entrant='" UINT32_FORMAT "' live_blobs='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   362
                      disconnected, made_not_entrant, CodeCache::nof_blobs(), CodeCache::unallocated_capacity());
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   363
    xtty->stamp();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   364
    xtty->end_elem();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   365
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   366
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   367
  // Shut off compiler. Sweeper will run exiting from this safepoint
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   368
  // and turn it back on if it clears enough space
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   369
  if (was_full()) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   370
    _last_was_full = os::javaTimeMillis();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   371
    CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   372
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   373
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   374
  // After two more traversals the sweeper will get rid of unrestored nmethods
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   375
  _was_full_traversal = _traversals;
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   376
#ifdef ASSERT
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   377
  jlong end = os::javaTimeMillis();
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   378
  if(PrintMethodFlushing && Verbose) {
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   379
    tty->print_cr("### sweeper: unload time: " INT64_FORMAT, end-start);
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   380
  }
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   381
#endif
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   382
}