src/hotspot/share/runtime/sweeper.cpp
author stefank
Tue, 26 Nov 2019 10:47:46 +0100
changeset 59290 97d13893ec3c
parent 58545 725244418646
permissions -rw-r--r--
8234748: Clean up atomic and orderAccess includes Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54385
9559ba212c18 8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents: 53651
diff changeset
     2
 * Copyright (c) 1997, 2019, 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: 5533
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5533
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: 5533
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: 6453
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    26
#include "code/codeCache.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    27
#include "code/compiledIC.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    28
#include "code/icBuffer.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    29
#include "code/nmethod.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    30
#include "compiler/compileBroker.hpp"
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
    31
#include "gc/shared/collectedHeap.hpp"
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
    32
#include "gc/shared/workgroup.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
    33
#include "jfr/jfrEvents.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46269
diff changeset
    34
#include "logging/log.hpp"
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46269
diff changeset
    35
#include "logging/logStream.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 48007
diff changeset
    36
#include "memory/allocation.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    37
#include "memory/resourceArea.hpp"
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
    38
#include "memory/universe.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    39
#include "oops/method.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49360
diff changeset
    40
#include "runtime/interfaceSupport.inline.hpp"
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
    41
#include "runtime/handshake.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    42
#include "runtime/mutexLocker.hpp"
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 50113
diff changeset
    43
#include "runtime/orderAccess.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    44
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    45
#include "runtime/sweeper.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22872
diff changeset
    46
#include "runtime/thread.inline.hpp"
52877
9e041366c764 8214850: Rename vm_operations.?pp files to vmOperations.?pp files
tschatzl
parents: 52857
diff changeset
    47
#include "runtime/vmOperations.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
    48
#include "runtime/vmThread.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    49
#include "utilities/events.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    50
#include "utilities/xmlstream.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    52
#ifdef ASSERT
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    53
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    54
#define SWEEP(nm) record_sweep(nm, __LINE__)
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    55
// Sweeper logging code
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    56
class SweeperRecord {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    57
 public:
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    58
  int traversal;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    59
  int compile_id;
47099
49f5fa3fc2ae 8186837: Memory ordering nmethod, _state and _stack_traversal_mark
rehn
parents: 46702
diff changeset
    60
  long traversal_mark;
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    61
  int state;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    62
  const char* kind;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    63
  address vep;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    64
  address uep;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    65
  int line;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    66
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    67
  void print() {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
    68
      tty->print_cr("traversal = %d compile_id = %d %s uep = " PTR_FORMAT " vep = "
47099
49f5fa3fc2ae 8186837: Memory ordering nmethod, _state and _stack_traversal_mark
rehn
parents: 46702
diff changeset
    69
                    PTR_FORMAT " state = %d traversal_mark %ld line = %d",
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    70
                    traversal,
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    71
                    compile_id,
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    72
                    kind == NULL ? "" : kind,
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32466
diff changeset
    73
                    p2i(uep),
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32466
diff changeset
    74
                    p2i(vep),
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    75
                    state,
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    76
                    traversal_mark,
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    77
                    line);
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    78
  }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    79
};
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    80
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    81
static int _sweep_index = 0;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    82
static SweeperRecord* _records = NULL;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    83
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    84
void NMethodSweeper::report_events(int id, address entry) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    85
  if (_records != NULL) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    86
    for (int i = _sweep_index; i < SweeperLogEntries; i++) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    87
      if (_records[i].uep == entry ||
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    88
          _records[i].vep == entry ||
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    89
          _records[i].compile_id == id) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    90
        _records[i].print();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    91
      }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    92
    }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    93
    for (int i = 0; i < _sweep_index; i++) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    94
      if (_records[i].uep == entry ||
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    95
          _records[i].vep == entry ||
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    96
          _records[i].compile_id == id) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    97
        _records[i].print();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    98
      }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
    99
    }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   100
  }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   101
}
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   102
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   103
void NMethodSweeper::report_events() {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   104
  if (_records != NULL) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   105
    for (int i = _sweep_index; i < SweeperLogEntries; i++) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   106
      // skip empty records
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   107
      if (_records[i].vep == NULL) continue;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   108
      _records[i].print();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   109
    }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   110
    for (int i = 0; i < _sweep_index; i++) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   111
      // skip empty records
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   112
      if (_records[i].vep == NULL) continue;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   113
      _records[i].print();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   114
    }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   115
  }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   116
}
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   117
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   118
void NMethodSweeper::record_sweep(CompiledMethod* nm, int line) {
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   119
  if (_records != NULL) {
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   120
    _records[_sweep_index].traversal = _traversals;
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   121
    _records[_sweep_index].traversal_mark = nm->is_nmethod() ? ((nmethod*)nm)->stack_traversal_mark() : 0;
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   122
    _records[_sweep_index].compile_id = nm->compile_id();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   123
    _records[_sweep_index].kind = nm->compile_kind();
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   124
    _records[_sweep_index].state = nm->get_state();
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   125
    _records[_sweep_index].vep = nm->verified_entry_point();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   126
    _records[_sweep_index].uep = nm->entry_point();
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   127
    _records[_sweep_index].line = line;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   128
    _sweep_index = (_sweep_index + 1) % SweeperLogEntries;
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   129
  }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   130
}
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   131
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   132
void NMethodSweeper::init_sweeper_log() {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   133
 if (LogSweeper && _records == NULL) {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   134
   // Create the ring buffer for the logging code
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   135
   _records = NEW_C_HEAP_ARRAY(SweeperRecord, SweeperLogEntries, mtGC);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   136
   memset(_records, 0, sizeof(SweeperRecord) * SweeperLogEntries);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   137
  }
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   138
}
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   139
#else
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   140
#define SWEEP(nm)
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   141
#endif
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   142
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52450
diff changeset
   143
CompiledMethodIterator NMethodSweeper::_current(CompiledMethodIterator::all_blobs); // Current compiled method
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   144
long     NMethodSweeper::_traversals                   = 0;    // Stack scan count, also sweep ID.
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 22208
diff changeset
   145
long     NMethodSweeper::_total_nof_code_cache_sweeps  = 0;    // Total number of full sweeps of the code cache
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   146
long     NMethodSweeper::_time_counter                 = 0;    // Virtual time used to periodically invoke sweeper
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   147
long     NMethodSweeper::_last_sweep                   = 0;    // Value of _time_counter when the last sweep happened
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   148
int      NMethodSweeper::_seen                         = 0;    // Nof. nmethod we have currently processed in current pass of CodeCache
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
53091
5bf5b773fc41 8215555: TieredCompilation C2 threads can excessively block handshakes
redestad
parents: 53085
diff changeset
   150
volatile bool NMethodSweeper::_should_sweep            = false;// Indicates if we should invoke the sweeper
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   151
volatile bool NMethodSweeper::_force_sweep             = false;// Indicates if we should force a sweep
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   152
volatile int  NMethodSweeper::_bytes_changed           = 0;    // Counts the total nmethod size if the nmethod changed from:
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   153
                                                               //   1) alive       -> not_entrant
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   154
                                                               //   2) not_entrant -> zombie
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 22208
diff changeset
   155
int    NMethodSweeper::_hotness_counter_reset_val       = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   157
long   NMethodSweeper::_total_nof_methods_reclaimed     = 0;   // Accumulated nof methods flushed
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   158
long   NMethodSweeper::_total_nof_c2_methods_reclaimed  = 0;   // Accumulated nof methods flushed
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   159
size_t NMethodSweeper::_total_flushed_size              = 0;   // Total number of bytes flushed from the code cache
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   160
Tickspan NMethodSweeper::_total_time_sweeping;                 // Accumulated time sweeping
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   161
Tickspan NMethodSweeper::_total_time_this_sweep;               // Total time this sweep
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   162
Tickspan NMethodSweeper::_peak_sweep_time;                     // Peak time for a full sweep
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   163
Tickspan NMethodSweeper::_peak_sweep_fraction_time;            // Peak time sweeping one fraction
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   164
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   165
class MarkActivationClosure: public CodeBlobClosure {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   166
public:
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   167
  virtual void do_code_blob(CodeBlob* cb) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   168
    assert(cb->is_nmethod(), "CodeBlob should be nmethod");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   169
    nmethod* nm = (nmethod*)cb;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   170
    nm->set_hotness_counter(NMethodSweeper::hotness_counter_reset_val());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   171
    // If we see an activation belonging to a non_entrant nmethod, we mark it.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   172
    if (nm->is_not_entrant()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   173
      nm->mark_as_seen_on_stack();
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   174
    }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   175
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   176
};
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   177
static MarkActivationClosure mark_activation_closure;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   178
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   179
class SetHotnessClosure: public CodeBlobClosure {
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   180
public:
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   181
  virtual void do_code_blob(CodeBlob* cb) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   182
    assert(cb->is_nmethod(), "CodeBlob should be nmethod");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   183
    nmethod* nm = (nmethod*)cb;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   184
    nm->set_hotness_counter(NMethodSweeper::hotness_counter_reset_val());
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   185
  }
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   186
};
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   187
static SetHotnessClosure set_hotness_closure;
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   188
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   189
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   190
int NMethodSweeper::hotness_counter_reset_val() {
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   191
  if (_hotness_counter_reset_val == 0) {
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   192
    _hotness_counter_reset_val = (ReservedCodeCacheSize < M) ? 1 : (ReservedCodeCacheSize / M) * 2;
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   193
  }
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   194
  return _hotness_counter_reset_val;
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   195
}
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   196
bool NMethodSweeper::wait_for_stack_scanning() {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   197
  return _current.end();
17132
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   198
}
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   199
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   200
class NMethodMarkingThreadClosure : public ThreadClosure {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   201
private:
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   202
  CodeBlobClosure* _cl;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   203
public:
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   204
  NMethodMarkingThreadClosure(CodeBlobClosure* cl) : _cl(cl) {}
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   205
  void do_thread(Thread* thread) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   206
    if (thread->is_Java_thread() && ! thread->is_Code_cache_sweeper_thread()) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   207
      JavaThread* jt = (JavaThread*) thread;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   208
      jt->nmethods_do(_cl);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   209
    }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   210
  }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   211
};
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   212
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   213
class NMethodMarkingTask : public AbstractGangTask {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   214
private:
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   215
  NMethodMarkingThreadClosure* _cl;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   216
public:
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   217
  NMethodMarkingTask(NMethodMarkingThreadClosure* cl) :
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   218
    AbstractGangTask("Parallel NMethod Marking"),
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   219
    _cl(cl) {
54385
9559ba212c18 8221102: Allow GC threads to participate in threads claiming protocol
kbarrett
parents: 53651
diff changeset
   220
    Threads::change_thread_claim_token();
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   221
  }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   222
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   223
  ~NMethodMarkingTask() {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   224
    Threads::assert_all_threads_claimed();
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   225
  }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   226
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   227
  void work(uint worker_id) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   228
    Threads::possibly_parallel_threads_do(true, _cl);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   229
  }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   230
};
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   231
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   232
/**
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   233
  * Scans the stacks of all Java threads and marks activations of not-entrant methods.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   234
  * No need to synchronize access, since 'mark_active_nmethods' is always executed at a
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   235
  * safepoint.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   236
  */
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   237
void NMethodSweeper::mark_active_nmethods() {
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   238
  CodeBlobClosure* cl = prepare_mark_active_nmethods();
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   239
  if (cl != NULL) {
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   240
    WorkGang* workers = Universe::heap()->get_safepoint_workers();
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   241
    if (workers != NULL) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   242
      NMethodMarkingThreadClosure tcl(cl);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   243
      NMethodMarkingTask task(&tcl);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   244
      workers->run_task(&task);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   245
    } else {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   246
      Threads::nmethods_do(cl);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   247
    }
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   248
  }
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   249
}
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   250
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   251
CodeBlobClosure* NMethodSweeper::prepare_mark_active_nmethods() {
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   252
#ifdef ASSERT
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   253
  if (ThreadLocalHandshakes) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   254
    assert(Thread::current()->is_Code_cache_sweeper_thread(), "must be executed under CodeCache_lock and in sweeper thread");
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   255
    assert_lock_strong(CodeCache_lock);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   256
  } else {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   257
    assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint");
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   258
  }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   259
#endif
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   260
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   261
  // If we do not want to reclaim not-entrant or zombie methods there is no need
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   262
  // to scan stacks
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   263
  if (!MethodFlushing) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   264
    return NULL;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   265
  }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   266
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   267
  // Increase time so that we can estimate when to invoke the sweeper again.
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   268
  _time_counter++;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   269
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   270
  // Check for restart
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   271
  assert(_current.method() == NULL, "should only happen between sweeper cycles");
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   272
  assert(wait_for_stack_scanning(), "should only happen between sweeper cycles");
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   273
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   274
  _seen = 0;
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52450
diff changeset
   275
  _current = CompiledMethodIterator(CompiledMethodIterator::all_blobs);
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   276
  // Initialize to first nmethod
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   277
  _current.next();
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   278
  _traversals += 1;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   279
  _total_time_this_sweep = Tickspan();
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   280
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   281
  if (PrintMethodFlushing) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   282
    tty->print_cr("### Sweep: stack traversal %ld", _traversals);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   283
  }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   284
  return &mark_activation_closure;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   285
}
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   286
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   287
CodeBlobClosure* NMethodSweeper::prepare_reset_hotness_counters() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint");
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   289
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   290
  // If we do not want to reclaim not-entrant or zombie methods there is no need
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   291
  // to scan stacks
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   292
  if (!MethodFlushing) {
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 46701
diff changeset
   293
    return NULL;
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   294
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   296
  // Increase time so that we can estimate when to invoke the sweeper again.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   297
  _time_counter++;
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   298
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // Check for restart
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   300
  if (_current.method() != NULL) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   301
    if (_current.method()->is_nmethod()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   302
      assert(CodeCache::find_blob_unsafe(_current.method()) == _current.method(), "Sweeper nmethod cached state invalid");
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40664
diff changeset
   303
    } else if (_current.method()->is_aot()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 40664
diff changeset
   304
      assert(CodeCache::find_blob_unsafe(_current.method()->code_begin()) == _current.method(), "Sweeper AOT method cached state invalid");
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   305
    } else {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   306
      ShouldNotReachHere();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   307
    }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   308
  }
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   309
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   310
  return &set_hotness_closure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
}
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   312
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   313
/**
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   314
  * This function triggers a VM operation that does stack scanning of active
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   315
  * methods. Stack scanning is mandatory for the sweeper to make progress.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   316
  */
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   317
void NMethodSweeper::do_stack_scanning() {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   318
  assert(!CodeCache_lock->owned_by_self(), "just checking");
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   319
  if (wait_for_stack_scanning()) {
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   320
    if (ThreadLocalHandshakes) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   321
      CodeBlobClosure* code_cl;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   322
      {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54385
diff changeset
   323
        MutexLocker ccl(CodeCache_lock, Mutex::_no_safepoint_check_flag);
51865
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   324
        code_cl = prepare_mark_active_nmethods();
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   325
      }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   326
      if (code_cl != NULL) {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   327
        NMethodMarkingThreadClosure tcl(code_cl);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   328
        Handshake::execute(&tcl);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   329
      }
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   330
    } else {
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   331
      VM_MarkActiveNMethods op;
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   332
      VMThread::execute(&op);
eb954a4b6083 8132849: Increased stop time in cleanup phase because of single-threaded walk of thread stacks in NMethodSweeper::mark_active_nmethods()
rkennke
parents: 50429
diff changeset
   333
    }
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   334
  }
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   335
}
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   336
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   337
void NMethodSweeper::sweeper_loop() {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   338
  bool timeout;
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   339
  while (true) {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   340
    {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   341
      ThreadBlockInVM tbivm(JavaThread::current());
54645
05aaccf7d558 8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
coleenp
parents: 54623
diff changeset
   342
      MonitorLocker waiter(CodeCache_lock, Mutex::_no_safepoint_check_flag);
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   343
      const long wait_time = 60*60*24 * 1000;
54645
05aaccf7d558 8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
coleenp
parents: 54623
diff changeset
   344
      timeout = waiter.wait(wait_time);
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   345
    }
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   346
    if (!timeout) {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   347
      possibly_sweep();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   348
    }
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   349
  }
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   350
}
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   351
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   352
/**
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   353
  * Wakes up the sweeper thread to possibly sweep.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   354
  */
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   355
void NMethodSweeper::notify(int code_blob_type) {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   356
  // Makes sure that we do not invoke the sweeper too often during startup.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   357
  double start_threshold = 100.0 / (double)StartAggressiveSweepingAt;
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   358
  double aggressive_sweep_threshold = MIN2(start_threshold, 1.1);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   359
  if (CodeCache::reverse_free_ratio(code_blob_type) >= aggressive_sweep_threshold) {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   360
    assert_locked_or_safepoint(CodeCache_lock);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   361
    CodeCache_lock->notify();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   362
  }
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   363
}
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   364
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   365
/**
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   366
  * Wakes up the sweeper thread and forces a sweep. Blocks until it finished.
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   367
  */
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   368
void NMethodSweeper::force_sweep() {
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   369
  ThreadBlockInVM tbivm(JavaThread::current());
54645
05aaccf7d558 8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
coleenp
parents: 54623
diff changeset
   370
  MonitorLocker waiter(CodeCache_lock, Mutex::_no_safepoint_check_flag);
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   371
  // Request forced sweep
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   372
  _force_sweep = true;
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   373
  while (_force_sweep) {
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   374
    // Notify sweeper that we want to force a sweep and wait for completion.
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   375
    // In case a sweep currently takes place we timeout and try again because
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   376
    // we want to enforce a full sweep.
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   377
    CodeCache_lock->notify();
54645
05aaccf7d558 8222988: Use MonitorLocker rather than MutexLocker when wait/notify used
coleenp
parents: 54623
diff changeset
   378
    waiter.wait(1000);
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   379
  }
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   380
}
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   381
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   382
/**
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   383
 * Handle a safepoint request
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   384
 */
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   385
void NMethodSweeper::handle_safepoint_request() {
52374
5ea020bcaa0d 8209495: NMethodSweeper::sweep_code_cache cause severe delays
rehn
parents: 51974
diff changeset
   386
  JavaThread* thread = JavaThread::current();
52450
2790da836dc3 8211403: Rename SafepointMechanism::poll(...)
rehn
parents: 52448
diff changeset
   387
  if (SafepointMechanism::should_block(thread)) {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   388
    if (PrintMethodFlushing && Verbose) {
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 33148
diff changeset
   389
      tty->print_cr("### Sweep at %d out of %d, yielding to safepoint", _seen, CodeCache::nmethod_count());
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   390
    }
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54385
diff changeset
   391
    MutexUnlocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   392
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   393
    ThreadBlockInVM tbivm(thread);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   394
    thread->java_suspend_self();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   395
  }
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   396
}
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   397
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   398
/**
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   399
 * This function invokes the sweeper if at least one of the three conditions is met:
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   400
 *    (1) The code cache is getting full
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   401
 *    (2) There are sufficient state changes in/since the last sweep.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   402
 *    (3) We have not been sweeping for 'some time'
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   403
 */
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   404
void NMethodSweeper::possibly_sweep() {
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   405
  assert(JavaThread::current()->thread_state() == _thread_in_vm, "must run in vm mode");
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   406
  // If there was no state change while nmethod sweeping, 'should_sweep' will be false.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   407
  // This is one of the two places where should_sweep can be set to true. The general
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   408
  // idea is as follows: If there is enough free space in the code cache, there is no
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   409
  // need to invoke the sweeper. The following formula (which determines whether to invoke
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   410
  // the sweeper or not) depends on the assumption that for larger ReservedCodeCacheSizes
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   411
  // we need less frequent sweeps than for smaller ReservedCodecCacheSizes. Furthermore,
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   412
  // the formula considers how much space in the code cache is currently used. Here are
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   413
  // some examples that will (hopefully) help in understanding.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   414
  //
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   415
  // Small ReservedCodeCacheSizes:  (e.g., < 16M) We invoke the sweeper every time, since
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   416
  //                                              the result of the division is 0. This
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   417
  //                                              keeps the used code cache size small
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   418
  //                                              (important for embedded Java)
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   419
  // Large ReservedCodeCacheSize :  (e.g., 256M + code cache is 10% full). The formula
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   420
  //                                              computes: (256 / 16) - 1 = 15
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   421
  //                                              As a result, we invoke the sweeper after
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   422
  //                                              15 invocations of 'mark_active_nmethods.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   423
  // Large ReservedCodeCacheSize:   (e.g., 256M + code Cache is 90% full). The formula
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   424
  //                                              computes: (256 / 16) - 10 = 6.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   425
  if (!_should_sweep) {
22208
fb1e20bd389f 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 21767
diff changeset
   426
    const int time_since_last_sweep = _time_counter - _last_sweep;
fb1e20bd389f 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 21767
diff changeset
   427
    // ReservedCodeCacheSize has an 'unsigned' type. We need a 'signed' type for max_wait_time,
fb1e20bd389f 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 21767
diff changeset
   428
    // since 'time_since_last_sweep' can be larger than 'max_wait_time'. If that happens using
fb1e20bd389f 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 21767
diff changeset
   429
    // an unsigned type would cause an underflow (wait_until_next_sweep becomes a large positive
fb1e20bd389f 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 21767
diff changeset
   430
    // value) that disables the intended periodic sweeps.
fb1e20bd389f 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 21767
diff changeset
   431
    const int max_wait_time = ReservedCodeCacheSize / (16 * M);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   432
    double wait_until_next_sweep = max_wait_time - time_since_last_sweep -
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   433
        MAX2(CodeCache::reverse_free_ratio(CodeBlobType::MethodProfiled),
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   434
             CodeCache::reverse_free_ratio(CodeBlobType::MethodNonProfiled));
22208
fb1e20bd389f 8029091: Bug in calculation of code cache sweeping interval
anoll
parents: 21767
diff changeset
   435
    assert(wait_until_next_sweep <= (double)max_wait_time, "Calculation of code cache sweeper interval is incorrect");
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   436
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   437
    if ((wait_until_next_sweep <= 0.0) || !CompileBroker::should_compile_new_jobs()) {
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   438
      _should_sweep = true;
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   439
    }
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   440
  }
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   441
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   442
  // Remember if this was a forced sweep
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   443
  bool forced = _force_sweep;
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   444
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   445
  // Force stack scanning if there is only 10% free space in the code cache.
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   446
  // We force stack scanning only if the non-profiled code heap gets full, since critical
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   447
  // allocations go to the non-profiled heap and we must be make sure that there is
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   448
  // enough space.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   449
  double free_percent = 1 / CodeCache::reverse_free_ratio(CodeBlobType::MethodNonProfiled) * 100;
51974
c5b97602cd4b 8211129: compiler/whitebox/ForceNMethodSweepTest.java fails after JDK-8132849
rkennke
parents: 51865
diff changeset
   450
  if (free_percent <= StartAggressiveSweepingAt || forced || _should_sweep) {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   451
    do_stack_scanning();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   452
  }
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   453
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   454
  if (_should_sweep || forced) {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   455
    init_sweeper_log();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   456
    sweep_code_cache();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   457
  }
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   458
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   459
  // We are done with sweeping the code cache once.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   460
  _total_nof_code_cache_sweeps++;
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   461
  _last_sweep = _time_counter;
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   462
  // Reset flag; temporarily disables sweeper
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   463
  _should_sweep = false;
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   464
  // If there was enough state change, 'possibly_enable_sweeper()'
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   465
  // sets '_should_sweep' to true
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   466
  possibly_enable_sweeper();
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   467
  // Reset _bytes_changed only if there was enough state change. _bytes_changed
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   468
  // can further increase by calls to 'report_state_change'.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   469
  if (_should_sweep) {
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   470
    _bytes_changed = 0;
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   471
  }
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   472
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   473
  if (forced) {
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   474
    // Notify requester that forced sweep finished
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   475
    assert(_force_sweep, "Should be a forced sweep");
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54385
diff changeset
   476
    MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
30205
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   477
    _force_sweep = false;
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   478
    CodeCache_lock->notify();
0bff2f15867f 8075214: SIGSEGV in nmethod sweeping
thartmann
parents: 29339
diff changeset
   479
  }
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   480
}
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   481
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   482
static void post_sweep_event(EventSweepCodeCache* event,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   483
                             const Ticks& start,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   484
                             const Ticks& end,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   485
                             s4 traversals,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   486
                             int swept,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   487
                             int flushed,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   488
                             int zombified) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   489
  assert(event != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   490
  assert(event->should_commit(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   491
  event->set_starttime(start);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   492
  event->set_endtime(end);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   493
  event->set_sweepId(traversals);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   494
  event->set_sweptCount(swept);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   495
  event->set_flushedCount(flushed);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   496
  event->set_zombifiedCount(zombified);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   497
  event->commit();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   498
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   499
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   500
void NMethodSweeper::sweep_code_cache() {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   501
  ResourceMark rm;
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 21727
diff changeset
   502
  Ticks sweep_start_counter = Ticks::now();
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   503
46269
7e725659ea12 8172286: CodeCacheFlushing message should be shown in UL
ysuenaga
parents: 42650
diff changeset
   504
  log_debug(codecache, sweep, start)("CodeCache flushing");
7e725659ea12 8172286: CodeCacheFlushing message should be shown in UL
ysuenaga
parents: 42650
diff changeset
   505
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   506
  int flushed_count                = 0;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   507
  int zombified_count              = 0;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   508
  int flushed_c2_count     = 0;
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   509
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   510
  if (PrintMethodFlushing && Verbose) {
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 33148
diff changeset
   511
    tty->print_cr("### Sweep at %d out of %d", _seen, CodeCache::nmethod_count());
17132
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   512
  }
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   513
20019
3e9220f93c61 8022883: Assertion failed: sweptCount >= flushedCount + markedCount + zombifiedCount
anoll
parents: 18025
diff changeset
   514
  int swept_count = 0;
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   515
  assert(!SafepointSynchronize::is_at_safepoint(), "should not be in safepoint when we get here");
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   516
  assert(!CodeCache_lock->owned_by_self(), "just checking");
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   517
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   518
  int freed_memory = 0;
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   519
  {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54385
diff changeset
   520
    MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   521
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   522
    while (!_current.end()) {
20019
3e9220f93c61 8022883: Assertion failed: sweptCount >= flushedCount + markedCount + zombifiedCount
anoll
parents: 18025
diff changeset
   523
      swept_count++;
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   524
      // Since we will give up the CodeCache_lock, always skip ahead
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   525
      // to the next nmethod.  Other blobs can be deleted by other
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   526
      // threads but nmethods are only reclaimed by the sweeper.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   527
      CompiledMethod* nm = _current.method();
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   528
      _current.next();
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   529
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   530
      // Now ready to process nmethod and give up CodeCache_lock
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   531
      {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54385
diff changeset
   532
        MutexUnlocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   533
        // Save information before potentially flushing the nmethod
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   534
        // Only flushing nmethods so size only matters for them.
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   535
        int size = nm->is_nmethod() ? ((nmethod*)nm)->total_size() : 0;
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   536
        bool is_c2_method = nm->is_compiled_by_c2();
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   537
        bool is_osr = nm->is_osr_method();
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   538
        int compile_id = nm->compile_id();
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   539
        intptr_t address = p2i(nm);
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   540
        const char* state_before = nm->state();
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   541
        const char* state_after = "";
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   542
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   543
        MethodStateChange type = process_compiled_method(nm);
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   544
        switch (type) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   545
          case Flushed:
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   546
            state_after = "flushed";
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   547
            freed_memory += size;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   548
            ++flushed_count;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   549
            if (is_c2_method) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   550
              ++flushed_c2_count;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   551
            }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   552
            break;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   553
          case MadeZombie:
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   554
            state_after = "made zombie";
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   555
            ++zombified_count;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   556
            break;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   557
          case None:
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   558
            break;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   559
          default:
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   560
           ShouldNotReachHere();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   561
        }
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   562
        if (PrintMethodFlushing && Verbose && type != None) {
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   563
          tty->print_cr("### %s nmethod %3d/" PTR_FORMAT " (%s) %s", is_osr ? "osr" : "", compile_id, address, state_before, state_after);
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   564
        }
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   565
      }
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   566
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   567
      _seen++;
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   568
      handle_safepoint_request();
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   569
    }
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   570
  }
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   571
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   572
  assert(_current.end(), "must have scanned the whole cache");
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   573
21767
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 21727
diff changeset
   574
  const Ticks sweep_end_counter = Ticks::now();
41eaa9a17059 8028128: Add a type safe alternative for working with counter based data
mgronlun
parents: 21727
diff changeset
   575
  const Tickspan sweep_time = sweep_end_counter - sweep_start_counter;
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   576
  {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54385
diff changeset
   577
    MutexLocker mu(NMethodSweeperStats_lock, Mutex::_no_safepoint_check_flag);
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   578
    _total_time_sweeping  += sweep_time;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   579
    _total_time_this_sweep += sweep_time;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   580
    _peak_sweep_fraction_time = MAX2(sweep_time, _peak_sweep_fraction_time);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   581
    _total_flushed_size += freed_memory;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   582
    _total_nof_methods_reclaimed += flushed_count;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   583
    _total_nof_c2_methods_reclaimed += flushed_c2_count;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   584
    _peak_sweep_time = MAX2(_peak_sweep_time, _total_time_this_sweep);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   585
  }
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   586
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   587
  EventSweepCodeCache event(UNTIMED);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   588
  if (event.should_commit()) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents: 49611
diff changeset
   589
    post_sweep_event(&event, sweep_start_counter, sweep_end_counter, (s4)_traversals, swept_count, flushed_count, zombified_count);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   590
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17132
diff changeset
   591
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   592
#ifdef ASSERT
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   593
  if(PrintMethodFlushing) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32466
diff changeset
   594
    tty->print_cr("### sweeper:      sweep time(" JLONG_FORMAT "): ", sweep_time.value());
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   595
  }
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   596
#endif
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   597
46269
7e725659ea12 8172286: CodeCacheFlushing message should be shown in UL
ysuenaga
parents: 42650
diff changeset
   598
  Log(codecache, sweep) log;
7e725659ea12 8172286: CodeCacheFlushing message should be shown in UL
ysuenaga
parents: 42650
diff changeset
   599
  if (log.is_debug()) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46269
diff changeset
   600
    LogStream ls(log.debug());
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46269
diff changeset
   601
    CodeCache::print_summary(&ls, false);
46269
7e725659ea12 8172286: CodeCacheFlushing message should be shown in UL
ysuenaga
parents: 42650
diff changeset
   602
  }
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   603
  log_sweep("finished");
17132
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   604
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   605
  // Sweeper is the only case where memory is released, check here if it
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   606
  // is time to restart the compiler. Only checking if there is a certain
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   607
  // amount of free memory in the code cache might lead to re-enabling
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   608
  // compilation although no memory has been released. For example, there are
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   609
  // cases when compilation was disabled although there is 4MB (or more) free
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   610
  // memory in the code cache. The reason is code cache fragmentation. Therefore,
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   611
  // it only makes sense to re-enable compilation if we have actually freed memory.
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   612
  // Note that typically several kB are released for sweeping 16MB of the code
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   613
  // cache. As a result, 'freed_memory' > 0 to restart the compiler.
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   614
  if (!CompileBroker::should_compile_new_jobs() && (freed_memory > 0)) {
17132
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   615
    CompileBroker::set_should_compile_new_jobs(CompileBroker::run_compilation);
46269
7e725659ea12 8172286: CodeCacheFlushing message should be shown in UL
ysuenaga
parents: 42650
diff changeset
   616
    log.debug("restart compiler");
17132
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   617
    log_sweep("restart_compiler");
dffd513b2a8c 8012547: Code cache flushing can get stuck reclaming of memory
neliasso
parents: 13728
diff changeset
   618
  }
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   619
}
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   620
21575
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   621
/**
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   622
 * This function updates the sweeper statistics that keep track of nmethods
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   623
 * state changes. If there is 'enough' state change, the sweeper is invoked
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   624
 * as soon as possible. There can be data races on _bytes_changed. The data
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   625
 * races are benign, since it does not matter if we loose a couple of bytes.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   626
 * In the worst case we call the sweeper a little later. Also, we are guaranteed
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   627
 * to invoke the sweeper if the code cache gets full.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   628
 */
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   629
void NMethodSweeper::report_state_change(nmethod* nm) {
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   630
  _bytes_changed += nm->total_size();
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   631
  possibly_enable_sweeper();
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   632
}
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   633
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   634
/**
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   635
 * Function determines if there was 'enough' state change in the code cache to invoke
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   636
 * the sweeper again. Currently, we determine 'enough' as more than 1% state change in
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   637
 * the code cache since the last sweep.
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   638
 */
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   639
void NMethodSweeper::possibly_enable_sweeper() {
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   640
  double percent_changed = ((double)_bytes_changed / (double)ReservedCodeCacheSize) * 100;
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   641
  if (percent_changed > 1.0) {
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   642
    _should_sweep = true;
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   643
  }
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   644
}
6a9645992cee 8027593: performance drop with constrained codecache starting with hs25 b111
anoll
parents: 20290
diff changeset
   645
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   646
class CompiledMethodMarker: public StackObj {
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   647
 private:
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   648
  CodeCacheSweeperThread* _thread;
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   649
 public:
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   650
  CompiledMethodMarker(CompiledMethod* cm) {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   651
    JavaThread* current = JavaThread::current();
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27017
diff changeset
   652
    assert (current->is_Code_cache_sweeper_thread(), "Must be");
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   653
    _thread = (CodeCacheSweeperThread*)current;
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52450
diff changeset
   654
    if (!cm->is_zombie() && !cm->is_unloading()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   655
      // Only expose live nmethods for scanning
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   656
      _thread->set_scanned_compiled_method(cm);
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   657
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   658
  }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   659
  ~CompiledMethodMarker() {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   660
    _thread->set_scanned_compiled_method(NULL);
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   661
  }
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   662
};
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   663
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   664
NMethodSweeper::MethodStateChange NMethodSweeper::process_compiled_method(CompiledMethod* cm) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   665
  assert(cm != NULL, "sanity");
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   666
  assert(!CodeCache_lock->owned_by_self(), "just checking");
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 4750
diff changeset
   667
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   668
  MethodStateChange result = None;
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   669
  // Make sure this nmethod doesn't get unloaded during the scan,
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   670
  // since safepoints may happen during acquired below locks.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   671
  CompiledMethodMarker nmm(cm);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   672
  SWEEP(cm);
9942
2e86734ba620 6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents: 9138
diff changeset
   673
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  // Skip methods that are currently referenced by the VM
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   675
  if (cm->is_locked_by_vm()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    // But still remember to clean-up inline caches for alive nmethods
53651
0331b08811ad 8216541: CompiledICHolders of VM locked unloaded nmethods are released too late
eosterlund
parents: 53091
diff changeset
   677
    if (cm->is_alive()) {
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   678
      // Clean inline caches that point to zombie/non-entrant/unloaded nmethods
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   679
      cm->cleanup_inline_caches(false);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   680
      SWEEP(cm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    }
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   682
    return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   685
  if (cm->is_zombie()) {
36818
b40330c06dea 8136458: Remove "marked for reclamation" nmethod state
thartmann
parents: 36802
diff changeset
   686
    // All inline caches that referred to this nmethod were cleaned in the
b40330c06dea 8136458: Remove "marked for reclamation" nmethod state
thartmann
parents: 36802
diff changeset
   687
    // previous sweeper cycle. Now flush the nmethod from the code cache.
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   688
    assert(!cm->is_locked_by_vm(), "must not flush locked Compiled Methods");
53651
0331b08811ad 8216541: CompiledICHolders of VM locked unloaded nmethods are released too late
eosterlund
parents: 53091
diff changeset
   689
    cm->flush();
36818
b40330c06dea 8136458: Remove "marked for reclamation" nmethod state
thartmann
parents: 36802
diff changeset
   690
    assert(result == None, "sanity");
b40330c06dea 8136458: Remove "marked for reclamation" nmethod state
thartmann
parents: 36802
diff changeset
   691
    result = Flushed;
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   692
  } else if (cm->is_not_entrant()) {
20290
2127dc70bce9 8020151: PSR:PERF Large performance regressions when code cache is filled
anoll
parents: 20019
diff changeset
   693
    // If there are no current activations of this method on the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
    // stack we can safely convert it to a zombie method
47099
49f5fa3fc2ae 8186837: Memory ordering nmethod, _state and _stack_traversal_mark
rehn
parents: 46702
diff changeset
   695
    OrderAccess::loadload(); // _stack_traversal_mark and _state
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   696
    if (cm->can_convert_to_zombie()) {
32401
cc58aeaec340 8075805: Crash while trying to release CompiledICHolder
thartmann
parents: 31348
diff changeset
   697
      // Code cache state change is tracked in make_zombie()
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   698
      cm->make_zombie();
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   699
      SWEEP(cm);
57891
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   700
      assert(result == None, "sanity");
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   701
      result = MadeZombie;
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   702
      assert(cm->is_zombie(), "nmethod must be zombie");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
      // Still alive, clean up its inline caches
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   705
      cm->cleanup_inline_caches(false);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   706
      SWEEP(cm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    }
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   708
  } else if (cm->is_unloaded()) {
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   709
    // Code is unloaded, so there are no activations on the stack.
57891
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   710
    // Convert the nmethod to zombie.
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   711
    // Code cache state change is tracked in make_zombie()
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   712
    cm->make_zombie();
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   713
    SWEEP(cm);
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   714
    assert(result == None, "sanity");
460f412c1358 8219708: Stop flushing OSR nmethods earlier in the sweeper
eosterlund
parents: 54645
diff changeset
   715
    result = MadeZombie;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  } else {
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   717
    if (cm->is_nmethod()) {
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   718
      possibly_flush((nmethod*)cm);
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   719
    }
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   720
    // Clean inline caches that point to zombie/non-entrant/unloaded nmethods
52385
5c679ec60888 8209189: Make CompiledMethod::do_unloading more concurrent
eosterlund
parents: 52384
diff changeset
   721
    cm->cleanup_inline_caches(false);
38133
78b95467b9f1 8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents: 36844
diff changeset
   722
    SWEEP(cm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  }
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27420
diff changeset
   724
  return result;
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   725
}
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3919
diff changeset
   726
24442
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   727
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   728
void NMethodSweeper::possibly_flush(nmethod* nm) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   729
  if (UseCodeCacheFlushing) {
52661
4f45c682eab0 8213755: Let nmethods be is_unloading() outside of safepoints
eosterlund
parents: 52450
diff changeset
   730
    if (!nm->is_locked_by_vm() && !nm->is_native_method() && !nm->is_not_installed() && !nm->is_unloading()) {
24442
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   731
      bool make_not_entrant = false;
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   732
36802
18b1db5a7e70 8023191: OSR nmethods should be flushed to free space in CodeCache
thartmann
parents: 34158
diff changeset
   733
      // Do not make native methods not-entrant
24442
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   734
      nm->dec_hotness_counter();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   735
      // Get the initial value of the hotness counter. This value depends on the
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   736
      // ReservedCodeCacheSize
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   737
      int reset_val = hotness_counter_reset_val();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   738
      int time_since_reset = reset_val - nm->hotness_counter();
31348
c28f02c7abb5 8077279: assert(ic->is_clean()) failed: IC should be clean
sjohanss
parents: 30205
diff changeset
   739
      int code_blob_type = CodeCache::get_code_blob_type(nm);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26578
diff changeset
   740
      double threshold = -reset_val + (CodeCache::reverse_free_ratio(code_blob_type) * NmethodSweepActivity);
24442
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   741
      // The less free space in the code cache we have - the bigger reverse_free_ratio() is.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   742
      // I.e., 'threshold' increases with lower available space in the code cache and a higher
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   743
      // NmethodSweepActivity. If the current hotness counter - which decreases from its initial
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   744
      // value until it is reset by stack walking - is smaller than the computed threshold, the
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   745
      // corresponding nmethod is considered for removal.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   746
      if ((NmethodSweepActivity > 0) && (nm->hotness_counter() < threshold) && (time_since_reset > MinPassesBeforeFlush)) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   747
        // A method is marked as not-entrant if the method is
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   748
        // 1) 'old enough': nm->hotness_counter() < threshold
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   749
        // 2) The method was in_use for a minimum amount of time: (time_since_reset > MinPassesBeforeFlush)
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   750
        //    The second condition is necessary if we are dealing with very small code cache
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   751
        //    sizes (e.g., <10m) and the code cache size is too small to hold all hot methods.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   752
        //    The second condition ensures that methods are not immediately made not-entrant
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   753
        //    after compilation.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   754
        make_not_entrant = true;
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   755
      }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   756
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   757
      // The stack-scanning low-cost detection may not see the method was used (which can happen for
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   758
      // flat profiles). Check the age counter for possible data.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   759
      if (UseCodeAging && make_not_entrant && (nm->is_compiled_by_c2() || nm->is_compiled_by_c1())) {
26799
0c349e16bbe8 8058564: Tiered compilation performance drop in PIT
iveresov
parents: 26796
diff changeset
   760
        MethodCounters* mc = nm->method()->get_method_counters(Thread::current());
24442
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   761
        if (mc != NULL) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   762
          // Snapshot the value as it's changed concurrently
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   763
          int age = mc->nmethod_age();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   764
          if (MethodCounters::is_nmethod_hot(age)) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   765
            // The method has gone through flushing, and it became relatively hot that it deopted
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   766
            // before we could take a look at it. Give it more time to appear in the stack traces,
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   767
            // proportional to the number of deopts.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   768
            MethodData* md = nm->method()->method_data();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   769
            if (md != NULL && time_since_reset > (int)(MinPassesBeforeFlush * (md->tenure_traps() + 1))) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   770
              // It's been long enough, we still haven't seen it on stack.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   771
              // Try to flush it, but enable counters the next time.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   772
              mc->reset_nmethod_age();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   773
            } else {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   774
              make_not_entrant = false;
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   775
            }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   776
          } else if (MethodCounters::is_nmethod_warm(age)) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   777
            // Method has counters enabled, and the method was used within
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   778
            // previous MinPassesBeforeFlush sweeps. Reset the counter. Stay in the existing
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   779
            // compiled state.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   780
            mc->reset_nmethod_age();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   781
            // delay the next check
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   782
            nm->set_hotness_counter(NMethodSweeper::hotness_counter_reset_val());
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   783
            make_not_entrant = false;
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   784
          } else if (MethodCounters::is_nmethod_age_unset(age)) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   785
            // No counters were used before. Set the counters to the detection
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   786
            // limit value. If the method is going to be used again it will be compiled
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   787
            // with counters that we're going to use for analysis the the next time.
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   788
            mc->reset_nmethod_age();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   789
          } else {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   790
            // Method was totally idle for 10 sweeps
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   791
            // The counter already has the initial value, flush it and may be recompile
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   792
            // later with counters
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   793
          }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   794
        }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   795
      }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   796
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   797
      if (make_not_entrant) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   798
        nm->make_not_entrant();
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   799
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   800
        // Code cache state change is tracked in make_not_entrant()
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   801
        if (PrintMethodFlushing && Verbose) {
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   802
          tty->print_cr("### Nmethod %d/" PTR_FORMAT "made not-entrant: hotness counter %d/%d threshold %f",
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 32466
diff changeset
   803
              nm->compile_id(), p2i(nm), nm->hotness_counter(), reset_val, threshold);
24442
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   804
        }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   805
      }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   806
    }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   807
  }
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   808
}
4d4ae31dea26 8032463: VirtualDispatch test timeout with DeoptimizeALot
iveresov
parents: 24424
diff changeset
   809
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   810
// Print out some state information about the current sweep and the
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   811
// state of the code cache if it's requested.
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   812
void NMethodSweeper::log_sweep(const char* msg, const char* format, ...) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   813
  if (PrintMethodFlushing) {
29339
f0b1b7788a51 8073257: compiler/codecache/stress/RandomAllocationTest.java + fastdebug + -XX:+LogCompilation, "allocating without ResourceMark"
thartmann
parents: 28163
diff changeset
   814
    ResourceMark rm;
9138
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   815
    stringStream s;
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   816
    // Dump code cache state into a buffer before locking the tty,
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   817
    // because log_state() will use locks causing lock conflicts.
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   818
    CodeCache::log_state(&s);
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   819
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   820
    ttyLocker ttyl;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   821
    tty->print("### sweeper: %s ", msg);
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   822
    if (format != NULL) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   823
      va_list ap;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   824
      va_start(ap, format);
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   825
      tty->vprint(format, ap);
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   826
      va_end(ap);
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   827
    }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
   828
    tty->print_cr("%s", s.as_string());
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   829
  }
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   830
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   831
  if (LogCompilation && (xtty != NULL)) {
29339
f0b1b7788a51 8073257: compiler/codecache/stress/RandomAllocationTest.java + fastdebug + -XX:+LogCompilation, "allocating without ResourceMark"
thartmann
parents: 28163
diff changeset
   832
    ResourceMark rm;
9138
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   833
    stringStream s;
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   834
    // Dump code cache state into a buffer before locking the tty,
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   835
    // because log_state() will use locks causing lock conflicts.
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   836
    CodeCache::log_state(&s);
35e4b04eadf4 7036236: VM crashes assert((!inside_attrs()) || is_error_reported()) failed ...
iveresov
parents: 8921
diff changeset
   837
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   838
    ttyLocker ttyl;
5926
a36f90d986b6 6968385: malformed xml in sweeper logging
never
parents: 5924
diff changeset
   839
    xtty->begin_elem("sweeper state='%s' traversals='" INTX_FORMAT "' ", msg, (intx)traversal_count());
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   840
    if (format != NULL) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   841
      va_list ap;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   842
      va_start(ap, format);
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   843
      xtty->vprint(format, ap);
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   844
      va_end(ap);
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   845
    }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24351
diff changeset
   846
    xtty->print("%s", s.as_string());
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   847
    xtty->stamp();
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   848
    xtty->end_elem();
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   849
  }
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5895
diff changeset
   850
}
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 22208
diff changeset
   851
49611
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49480
diff changeset
   852
void NMethodSweeper::print(outputStream* out) {
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 22208
diff changeset
   853
  ttyLocker ttyl;
49611
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49480
diff changeset
   854
  out = (out == NULL) ? tty : out;
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49480
diff changeset
   855
  out->print_cr("Code cache sweeper statistics:");
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49480
diff changeset
   856
  out->print_cr("  Total sweep time:                %1.0lf ms", (double)_total_time_sweeping.value()/1000000);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49480
diff changeset
   857
  out->print_cr("  Total number of full sweeps:     %ld", _total_nof_code_cache_sweeps);
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49480
diff changeset
   858
  out->print_cr("  Total number of flushed methods: %ld (thereof %ld C2 methods)", _total_nof_methods_reclaimed,
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 22208
diff changeset
   859
                                                    _total_nof_c2_methods_reclaimed);
49611
973c9504178e 8198691: CodeHeap State Analytics
lucy
parents: 49480
diff changeset
   860
  out->print_cr("  Total size of flushed methods:   " SIZE_FORMAT " kB", _total_flushed_size/K);
22210
b0408ba029f6 8025277: Add -XX: flag to print code cache sweeper statistics
anoll
parents: 22208
diff changeset
   861
}