hotspot/src/share/vm/code/codeCache.cpp
author rbackman
Mon, 11 May 2015 09:44:07 +0200
changeset 30628 3c15b4a3bf4d
parent 30590 14f7f48c1377
child 30633 eaf7c74a3fb9
permissions -rw-r--r--
8079797: assert(index >= 0 && index < _count) failed: check Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
     2
 * Copyright (c) 1997, 2015, 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: 7108
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    26
#include "code/codeBlob.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    27
#include "code/codeCache.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    28
#include "code/compiledIC.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    29
#include "code/dependencies.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    30
#include "code/icBuffer.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    31
#include "code/nmethod.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    32
#include "code/pcDesc.hpp"
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
    33
#include "compiler/compileBroker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    34
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    35
#include "memory/gcLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    36
#include "memory/iterator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    37
#include "memory/resourceArea.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    38
#include "oops/method.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    39
#include "oops/objArrayOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    40
#include "oops/oop.inline.hpp"
29084
1b732f2836ce 8073387: Move VerifyOopClosures out from genOopClosures.hpp
stefank
parents: 28730
diff changeset
    41
#include "oops/verifyOopClosure.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    42
#include "runtime/handles.inline.hpp"
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
    43
#include "runtime/arguments.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    44
#include "runtime/icache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    45
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    46
#include "runtime/mutexLocker.hpp"
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
    47
#include "runtime/sweeper.hpp"
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    48
#include "runtime/compilationPolicy.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    49
#include "services/memoryService.hpp"
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
    50
#include "trace/tracing.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7108
diff changeset
    51
#include "utilities/xmlstream.hpp"
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    52
#ifdef COMPILER1
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    53
#include "c1/c1_Compilation.hpp"
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    54
#include "c1/c1_Compiler.hpp"
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    55
#endif
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    56
#ifdef COMPILER2
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    57
#include "opto/c2compiler.hpp"
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    58
#include "opto/compile.hpp"
26805
73f3e9ac86f5 8058716: Add include missing in 8015774
goetz
parents: 26796
diff changeset
    59
#include "opto/node.hpp"
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
    60
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// Helper class for printing in CodeCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
class CodeBlob_sizes {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  int count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  int total_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  int header_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  int code_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  int stub_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  int relocation_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  int scopes_oop_size;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    72
  int scopes_metadata_size;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  int scopes_data_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  int scopes_pcs_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  CodeBlob_sizes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    count            = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    total_size       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    header_size      = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    code_size        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    stub_size        = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    relocation_size  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    scopes_oop_size  = 0;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    85
    scopes_metadata_size  = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    scopes_data_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    scopes_pcs_size  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  int total()                                    { return total_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  bool is_empty()                                { return count == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void print(const char* title) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23214
diff changeset
    94
    tty->print_cr(" #%d %s = %dK (hdr %d%%,  loc %d%%, code %d%%, stub %d%%, [oops %d%%, metadata %d%%, data %d%%, pcs %d%%])",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                  count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                  title,
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23214
diff changeset
    97
                  (int)(total() / K),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
                  header_size             * 100 / total_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                  relocation_size         * 100 / total_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                  code_size               * 100 / total_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                  stub_size               * 100 / total_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                  scopes_oop_size         * 100 / total_size,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   103
                  scopes_metadata_size    * 100 / total_size,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                  scopes_data_size        * 100 / total_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                  scopes_pcs_size         * 100 / total_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  void add(CodeBlob* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    total_size       += cb->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    header_size      += cb->header_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    relocation_size  += cb->relocation_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    if (cb->is_nmethod()) {
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 5533
diff changeset
   114
      nmethod* nm = cb->as_nmethod_or_null();
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5924
diff changeset
   115
      code_size        += nm->insts_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      stub_size        += nm->stub_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 5533
diff changeset
   118
      scopes_oop_size  += nm->oops_size();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   119
      scopes_metadata_size  += nm->metadata_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      scopes_data_size += nm->scopes_data_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      scopes_pcs_size  += nm->scopes_pcs_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    } else {
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5924
diff changeset
   123
      code_size        += cb->code_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   128
// Iterate over all CodeHeaps
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   129
#define FOR_ALL_HEAPS(heap) for (GrowableArrayIterator<CodeHeap*> heap = _heaps->begin(); heap != _heaps->end(); ++heap)
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   130
// Iterate over all CodeBlobs (cb) on the given CodeHeap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   131
#define FOR_ALL_BLOBS(cb, heap) for (CodeBlob* cb = first_blob(heap); cb != NULL; cb = next_blob(heap, cb))
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   133
address CodeCache::_low_bound = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   134
address CodeCache::_high_bound = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
int CodeCache::_number_of_blobs = 0;
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   136
int CodeCache::_number_of_adapters = 0;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   137
int CodeCache::_number_of_nmethods = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
int CodeCache::_number_of_nmethods_with_dependencies = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
bool CodeCache::_needs_cache_clean = false;
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   140
nmethod* CodeCache::_scavenge_root_nmethods = NULL;
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
   141
int CodeCache::_codemem_full_count = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   143
// Initialize array of CodeHeaps
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   144
GrowableArray<CodeHeap*>* CodeCache::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, true);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   145
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   146
void CodeCache::initialize_heaps() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   147
  // Determine size of compiler buffers
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   148
  size_t code_buffers_size = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   149
#ifdef COMPILER1
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   150
  // C1 temporary code buffers (see Compiler::init_buffer_blob())
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   151
  const int c1_count = CompilationPolicy::policy()->compiler_count(CompLevel_simple);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   152
  code_buffers_size += c1_count * Compiler::code_buffer_size();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   153
#endif
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   154
#ifdef COMPILER2
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   155
  // C2 scratch buffers (see Compile::init_scratch_buffer_blob())
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   156
  const int c2_count = CompilationPolicy::policy()->compiler_count(CompLevel_full_optimization);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   157
  // Initial size of constant table (this may be increased if a compiled method needs more space)
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   158
  code_buffers_size += c2_count * C2Compiler::initial_code_buffer_size();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   159
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   161
  // Calculate default CodeHeap sizes if not set by user
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   162
  if (!FLAG_IS_CMDLINE(NonNMethodCodeHeapSize) && !FLAG_IS_CMDLINE(ProfiledCodeHeapSize)
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   163
      && !FLAG_IS_CMDLINE(NonProfiledCodeHeapSize)) {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   164
    // Increase default NonNMethodCodeHeapSize to account for compiler buffers
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   165
    FLAG_SET_ERGO(uintx, NonNMethodCodeHeapSize, NonNMethodCodeHeapSize + code_buffers_size);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   166
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   167
    // Check if we have enough space for the non-nmethod code heap
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   168
    if (ReservedCodeCacheSize > NonNMethodCodeHeapSize) {
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   169
      // Use the default value for NonNMethodCodeHeapSize and one half of the
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   170
      // remaining size for non-profiled methods and one half for profiled methods
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   171
      size_t remaining_size = ReservedCodeCacheSize - NonNMethodCodeHeapSize;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   172
      size_t profiled_size = remaining_size / 2;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   173
      size_t non_profiled_size = remaining_size - profiled_size;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   174
      FLAG_SET_ERGO(uintx, ProfiledCodeHeapSize, profiled_size);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   175
      FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, non_profiled_size);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   176
    } else {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   177
      // Use all space for the non-nmethod heap and set other heaps to minimal size
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   178
      FLAG_SET_ERGO(uintx, NonNMethodCodeHeapSize, ReservedCodeCacheSize - os::vm_page_size() * 2);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   179
      FLAG_SET_ERGO(uintx, ProfiledCodeHeapSize, os::vm_page_size());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   180
      FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, os::vm_page_size());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   181
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   182
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   184
  // We do not need the profiled CodeHeap, use all space for the non-profiled CodeHeap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   185
  if(!heap_available(CodeBlobType::MethodProfiled)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   186
    FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, NonProfiledCodeHeapSize + ProfiledCodeHeapSize);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   187
    FLAG_SET_ERGO(uintx, ProfiledCodeHeapSize, 0);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   188
  }
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   189
  // We do not need the non-profiled CodeHeap, use all space for the non-nmethod CodeHeap
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   190
  if(!heap_available(CodeBlobType::MethodNonProfiled)) {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   191
    FLAG_SET_ERGO(uintx, NonNMethodCodeHeapSize, NonNMethodCodeHeapSize + NonProfiledCodeHeapSize);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   192
    FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, 0);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   193
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   194
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   195
  // Make sure we have enough space for VM internal code
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   196
  uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   197
  if (NonNMethodCodeHeapSize < (min_code_cache_size + code_buffers_size)) {
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   198
    vm_exit_during_initialization("Not enough space in non-nmethod code heap to run VM.");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   199
  }
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   200
  guarantee(NonProfiledCodeHeapSize + ProfiledCodeHeapSize + NonNMethodCodeHeapSize <= ReservedCodeCacheSize, "Size check");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   201
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   202
  // Align CodeHeaps
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   203
  size_t alignment = heap_alignment();
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   204
  size_t non_method_size = align_size_up(NonNMethodCodeHeapSize, alignment);
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   205
  size_t profiled_size   = align_size_down(ProfiledCodeHeapSize, alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   207
  // Reserve one continuous chunk of memory for CodeHeaps and split it into
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   208
  // parts for the individual heaps. The memory layout looks like this:
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   209
  // ---------- high -----------
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   210
  //    Non-profiled nmethods
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   211
  //      Profiled nmethods
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   212
  //         Non-nmethods
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   213
  // ---------- low ------------
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   214
  ReservedCodeSpace rs = reserve_heap_memory(ReservedCodeCacheSize);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   215
  ReservedSpace non_method_space    = rs.first_part(non_method_size);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   216
  ReservedSpace rest                = rs.last_part(non_method_size);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   217
  ReservedSpace profiled_space      = rest.first_part(profiled_size);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   218
  ReservedSpace non_profiled_space  = rest.last_part(profiled_size);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   219
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   220
  // Non-nmethods (stubs, adapters, ...)
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   221
  add_heap(non_method_space, "CodeHeap 'non-nmethods'", CodeBlobType::NonNMethod);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   222
  // Tier 2 and tier 3 (profiled) methods
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   223
  add_heap(profiled_space, "CodeHeap 'profiled nmethods'", CodeBlobType::MethodProfiled);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   224
  // Tier 1 and tier 4 (non-profiled) methods and native methods
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   225
  add_heap(non_profiled_space, "CodeHeap 'non-profiled nmethods'", CodeBlobType::MethodNonProfiled);
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   226
}
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   227
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   228
size_t CodeCache::heap_alignment() {
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   229
  // If large page support is enabled, align code heaps according to large
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   230
  // page size to make sure that code cache is covered by large pages.
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   231
  const size_t page_size = os::can_execute_large_page_memory() ?
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   232
             os::page_size_for_region_unaligned(ReservedCodeCacheSize, 8) :
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   233
             os::vm_page_size();
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   234
  return MAX2(page_size, (size_t) os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   237
ReservedCodeSpace CodeCache::reserve_heap_memory(size_t size) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   238
  // Determine alignment
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   239
  const size_t page_size = os::can_execute_large_page_memory() ?
28631
a56cae1b428d 8066875: VirtualSpace does not use large pages
ehelin
parents: 28374
diff changeset
   240
          MIN2(os::page_size_for_region_aligned(InitialCodeCacheSize, 8),
a56cae1b428d 8066875: VirtualSpace does not use large pages
ehelin
parents: 28374
diff changeset
   241
               os::page_size_for_region_aligned(size, 8)) :
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   242
          os::vm_page_size();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   243
  const size_t granularity = os::vm_allocation_granularity();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   244
  const size_t r_align = MAX2(page_size, granularity);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   245
  const size_t r_size = align_size_up(size, r_align);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   246
  const size_t rs_align = page_size == (size_t) os::vm_page_size() ? 0 :
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   247
    MAX2(page_size, granularity);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   249
  ReservedCodeSpace rs(r_size, rs_align, rs_align > 0);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   250
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   251
  // Initialize bounds
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   252
  _low_bound = (address)rs.base();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   253
  _high_bound = _low_bound + rs.size();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   254
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   255
  return rs;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   256
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   257
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   258
bool CodeCache::heap_available(int code_blob_type) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   259
  if (!SegmentedCodeCache) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   260
    // No segmentation: use a single code heap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   261
    return (code_blob_type == CodeBlobType::All);
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26942
diff changeset
   262
  } else if (Arguments::mode() == Arguments::_int) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   263
    // Interpreter only: we don't need any method code heaps
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   264
    return (code_blob_type == CodeBlobType::NonNMethod);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   265
  } else if (TieredCompilation && (TieredStopAtLevel > CompLevel_simple)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   266
    // Tiered compilation: use all code heaps
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   267
    return (code_blob_type < CodeBlobType::All);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   268
  } else {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   269
    // No TieredCompilation: we only need the non-nmethod and non-profiled code heap
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   270
    return (code_blob_type == CodeBlobType::NonNMethod) ||
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   271
           (code_blob_type == CodeBlobType::MethodNonProfiled);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   272
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
27410
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   275
const char* CodeCache::get_code_heap_flag_name(int code_blob_type) {
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   276
  switch(code_blob_type) {
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   277
  case CodeBlobType::NonNMethod:
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   278
    return "NonNMethodCodeHeapSize";
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   279
    break;
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   280
  case CodeBlobType::MethodNonProfiled:
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   281
    return "NonProfiledCodeHeapSize";
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   282
    break;
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   283
  case CodeBlobType::MethodProfiled:
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   284
    return "ProfiledCodeHeapSize";
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   285
    break;
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   286
  }
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   287
  ShouldNotReachHere();
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   288
  return NULL;
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   289
}
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
   290
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   291
void CodeCache::add_heap(ReservedSpace rs, const char* name, int code_blob_type) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   292
  // Check if heap is needed
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   293
  if (!heap_available(code_blob_type)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   294
    return;
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 5247
diff changeset
   295
  }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   296
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   297
  // Create CodeHeap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   298
  CodeHeap* heap = new CodeHeap(name, code_blob_type);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   299
  _heaps->append(heap);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   300
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   301
  // Reserve Space
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   302
  size_t size_initial = MIN2(InitialCodeCacheSize, rs.size());
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   303
  size_initial = round_to(size_initial, os::vm_page_size());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   304
  if (!heap->reserve(rs, size_initial, CodeCacheSegmentSize)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   305
    vm_exit_during_initialization("Could not reserve enough space for code cache");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   306
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   307
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   308
  // Register the CodeHeap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   309
  MemoryService::add_code_heap_memory_pool(heap, name);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   310
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   311
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents: 27420
diff changeset
   312
CodeHeap* CodeCache::get_code_heap(const CodeBlob* cb) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   313
  assert(cb != NULL, "CodeBlob is null");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   314
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   315
    if ((*heap)->contains(cb)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   316
      return *heap;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   317
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   318
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   319
  ShouldNotReachHere();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   320
  return NULL;
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 5247
diff changeset
   321
}
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 5247
diff changeset
   322
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   323
CodeHeap* CodeCache::get_code_heap(int code_blob_type) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   324
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   325
    if ((*heap)->accepts(code_blob_type)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   326
      return *heap;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   327
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   328
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   329
  return NULL;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   330
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   331
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   332
CodeBlob* CodeCache::first_blob(CodeHeap* heap) {
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 5247
diff changeset
   333
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   334
  assert(heap != NULL, "heap is null");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   335
  return (CodeBlob*)heap->first();
5533
e8d9ff82ec62 6950075: nmethod sweeper should operate concurrently
never
parents: 5247
diff changeset
   336
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   338
CodeBlob* CodeCache::first_blob(int code_blob_type) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   339
  if (heap_available(code_blob_type)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   340
    return first_blob(get_code_heap(code_blob_type));
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   341
  } else {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   342
    return NULL;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   343
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   344
}
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
   345
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   346
CodeBlob* CodeCache::next_blob(CodeHeap* heap, CodeBlob* cb) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   347
  assert_locked_or_safepoint(CodeCache_lock);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   348
  assert(heap != NULL, "heap is null");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   349
  return (CodeBlob*)heap->next(cb);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   350
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   351
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   352
CodeBlob* CodeCache::next_blob(CodeBlob* cb) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   353
  return next_blob(get_code_heap(cb), cb);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   354
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   355
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   356
/**
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   357
 * Do not seize the CodeCache lock here--if the caller has not
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   358
 * already done so, we are going to lose bigtime, since the code
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   359
 * cache will contain a garbage CodeBlob until the caller can
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   360
 * run the constructor for the CodeBlob subclass he is busy
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   361
 * instantiating.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   362
 */
29338
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   363
CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool strict) {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   364
  // Possibly wakes up the sweeper thread.
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   365
  NMethodSweeper::notify(code_blob_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  assert_locked_or_safepoint(CodeCache_lock);
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   367
  assert(size > 0, err_msg_res("Code cache allocation request must be > 0 but is %d", size));
24439
252c634b2e1c 8029343: CodeCache::allocate increments '_number_of_blobs' even if allocation fails.
anoll
parents: 23214
diff changeset
   368
  if (size <= 0) {
252c634b2e1c 8029343: CodeCache::allocate increments '_number_of_blobs' even if allocation fails.
anoll
parents: 23214
diff changeset
   369
    return NULL;
252c634b2e1c 8029343: CodeCache::allocate increments '_number_of_blobs' even if allocation fails.
anoll
parents: 23214
diff changeset
   370
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  CodeBlob* cb = NULL;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   372
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   373
  // Get CodeHeap for the given CodeBlobType
26942
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   374
  CodeHeap* heap = get_code_heap(code_blob_type);
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   375
  assert(heap != NULL, "heap is null");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   376
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  while (true) {
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   378
    cb = (CodeBlob*)heap->allocate(size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    if (cb != NULL) break;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   380
    if (!heap->expand_by(CodeCacheExpansionSize)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      // Expansion failed
29338
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   382
      if (SegmentedCodeCache && !strict) {
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   383
        // Fallback solution: Try to store code in another code heap.
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   384
        // Note that in the sweeper, we check the reverse_free_ratio of the code heap
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   385
        // and force stack scanning if less than 10% of the code heap are free.
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   386
        int type = code_blob_type;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   387
        switch (type) {
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   388
        case CodeBlobType::NonNMethod:
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   389
          type = CodeBlobType::MethodNonProfiled;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   390
          strict = false;   // Allow recursive search for other heaps
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   391
          break;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   392
        case CodeBlobType::MethodProfiled:
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   393
          type = CodeBlobType::MethodNonProfiled;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   394
          strict = true;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   395
          break;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   396
        case CodeBlobType::MethodNonProfiled:
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   397
          type = CodeBlobType::MethodProfiled;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   398
          strict = true;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   399
          break;
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   400
        }
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   401
        if (heap_available(type)) {
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   402
          return allocate(size, type, strict);
92297a8bd48e 8072774: bigapps/Weblogic+medrec/nowarnings fails due to CodeHeap 'profiled nmethods' exhaustion
thartmann
parents: 28730
diff changeset
   403
        }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   404
      }
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   405
      MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   406
      CompileBroker::handle_full_code_cache(code_blob_type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    if (PrintCodeCacheExtension) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      ResourceMark rm;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   411
      if (SegmentedCodeCache) {
26918
4e1761669426 8059137: MemoryPoolMXBeans for different code heaps should contain 'Code heap' in their names
thartmann
parents: 26809
diff changeset
   412
        tty->print("%s", heap->name());
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   413
      } else {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
   414
        tty->print("CodeCache");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   415
      }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   416
      tty->print_cr(" extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (" SSIZE_FORMAT " bytes)",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   417
                    (intptr_t)heap->low_boundary(), (intptr_t)heap->high(),
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   418
                    (address)heap->high() - (address)heap->low_boundary());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  }
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   421
  print_trace("allocation", cb, size);
24439
252c634b2e1c 8029343: CodeCache::allocate increments '_number_of_blobs' even if allocation fails.
anoll
parents: 23214
diff changeset
   422
  _number_of_blobs++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  return cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
void CodeCache::free(CodeBlob* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  assert_locked_or_safepoint(CodeCache_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   429
  print_trace("free", cb);
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   430
  if (cb->is_nmethod()) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   431
    _number_of_nmethods--;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   432
    if (((nmethod *)cb)->has_dependencies()) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   433
      _number_of_nmethods_with_dependencies--;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   434
    }
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   435
  }
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   436
  if (cb->is_adapter_blob()) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   437
    _number_of_adapters--;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  _number_of_blobs--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   441
  // Get heap for given CodeBlob and deallocate
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   442
  get_code_heap(cb)->deallocate(cb);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  assert(_number_of_blobs >= 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
void CodeCache::commit(CodeBlob* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  // this is called by nmethod::nmethod, which must already own CodeCache_lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  assert_locked_or_safepoint(CodeCache_lock);
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   450
  if (cb->is_nmethod()) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   451
    _number_of_nmethods++;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   452
    if (((nmethod *)cb)->has_dependencies()) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   453
      _number_of_nmethods_with_dependencies++;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   454
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  }
5924
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   456
  if (cb->is_adapter_blob()) {
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   457
    _number_of_adapters++;
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   458
  }
dc9d04930c82 6965184: possible races in make_not_entrant_or_zombie
never
parents: 5702
diff changeset
   459
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // flush the hardware I-cache
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5924
diff changeset
   461
  ICache::invalidate_range(cb->content_begin(), cb->content_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
bool CodeCache::contains(void *p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  // It should be ok to call contains without holding a lock
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   466
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   467
    if ((*heap)->contains(p)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   468
      return true;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   469
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   470
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   471
  return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   474
// This method is safe to call without holding the CodeCache_lock, as long as a dead CodeBlob is not
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   475
// looked up (i.e., one that has been marked for deletion). It only depends on the _segmap to contain
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
// valid indices, which it will always do, as long as the CodeBlob is not in the process of being recycled.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
CodeBlob* CodeCache::find_blob(void* start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  CodeBlob* result = find_blob_unsafe(start);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
   479
  // We could potentially look up non_entrant methods
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   480
  guarantee(result == NULL || !result->is_zombie() || result->is_locked_by_vm() || is_error_reported(), "unsafe access to zombie method");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   484
// Lookup that does not fail if you lookup a zombie method (if you call this, be sure to know
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   485
// what you are doing)
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   486
CodeBlob* CodeCache::find_blob_unsafe(void* start) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   487
  // NMT can walk the stack before code cache is created
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   488
  if (_heaps == NULL || _heaps->is_empty()) return NULL;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   489
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   490
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   491
    CodeBlob* result = (CodeBlob*) (*heap)->find_start(start);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   492
    if (result != NULL && result->blob_contains((address)start)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   493
      return result;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   494
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   495
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   496
  return NULL;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   497
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   498
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
nmethod* CodeCache::find_nmethod(void* start) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   500
  CodeBlob* cb = find_blob(start);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   501
  assert(cb->is_nmethod(), "did not find an nmethod");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  return (nmethod*)cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
void CodeCache::blobs_do(void f(CodeBlob* nm)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   507
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   508
    FOR_ALL_BLOBS(cb, *heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   509
      f(cb);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   510
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
void CodeCache::nmethods_do(void f(nmethod* nm)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   516
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   517
  while(iter.next()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   518
    f(iter.method());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   522
void CodeCache::alive_nmethods_do(void f(nmethod* nm)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   523
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   524
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   525
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   526
    f(iter.method());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   527
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   528
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
int CodeCache::alignment_unit() {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   531
  return (int)_heaps->first()->alignment_unit();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
int CodeCache::alignment_offset() {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   535
  return (int)_heaps->first()->alignment_offset();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   538
// Mark nmethods for unloading if they contain otherwise unreachable oops.
13878
6e6a462a6cff 7200470: KeepAliveClosure not needed in CodeCache::do_unloading
brutisso
parents: 13728
diff changeset
   539
void CodeCache::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   541
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   542
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   543
    iter.method()->do_unloading(is_alive, unloading_occurred);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   547
void CodeCache::blobs_do(CodeBlobClosure* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   549
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   550
    FOR_ALL_BLOBS(cb, *heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   551
      if (cb->is_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   552
        f->do_code_blob(cb);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   553
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   554
#ifdef ASSERT
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   555
        if (cb->is_nmethod())
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   556
        ((nmethod*)cb)->verify_scavenge_root_oops();
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   557
#endif //ASSERT
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   558
      }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   559
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   563
// Walk the list of methods which might contain non-perm oops.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   564
void CodeCache::scavenge_root_nmethods_do(CodeBlobClosure* f) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   565
  assert_locked_or_safepoint(CodeCache_lock);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   566
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   567
  if (UseG1GC) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   568
    return;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   569
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   570
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   571
  debug_only(mark_scavenge_root_nmethods());
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   572
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   573
  for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   574
    debug_only(cur->clear_scavenge_root_marked());
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   575
    assert(cur->scavenge_root_not_marked(), "");
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   576
    assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   577
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   578
    bool is_live = (!cur->is_zombie() && !cur->is_unloaded());
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   579
#ifndef PRODUCT
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   580
    if (TraceScavenge) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   581
      cur->print_on(tty, is_live ? "scavenge root" : "dead scavenge root"); tty->cr();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   582
    }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   583
#endif //PRODUCT
5247
c2b4e525b3e5 6940520: CodeCache::scavenge_root_nmethods_do must fix oop relocations
twisti
parents: 4750
diff changeset
   584
    if (is_live) {
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   585
      // Perform cur->oops_do(f), maybe just once per nmethod.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   586
      f->do_code_blob(cur);
5247
c2b4e525b3e5 6940520: CodeCache::scavenge_root_nmethods_do must fix oop relocations
twisti
parents: 4750
diff changeset
   587
    }
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   588
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   589
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   590
  // Check for stray marks.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   591
  debug_only(verify_perm_nmethods(NULL));
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   592
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   593
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   594
void CodeCache::add_scavenge_root_nmethod(nmethod* nm) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   595
  assert_locked_or_safepoint(CodeCache_lock);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   596
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   597
  if (UseG1GC) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   598
    return;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   599
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   600
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   601
  nm->set_on_scavenge_root_list();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   602
  nm->set_scavenge_root_link(_scavenge_root_nmethods);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   603
  set_scavenge_root_nmethods(nm);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   604
  print_trace("add_scavenge_root", nm);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   605
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   606
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   607
void CodeCache::drop_scavenge_root_nmethod(nmethod* nm) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   608
  assert_locked_or_safepoint(CodeCache_lock);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   609
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   610
  if (UseG1GC) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   611
    return;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   612
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   613
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   614
  print_trace("drop_scavenge_root", nm);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   615
  nmethod* last = NULL;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   616
  nmethod* cur = scavenge_root_nmethods();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   617
  while (cur != NULL) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   618
    nmethod* next = cur->scavenge_root_link();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   619
    if (cur == nm) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   620
      if (last != NULL)
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   621
            last->set_scavenge_root_link(next);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   622
      else  set_scavenge_root_nmethods(next);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   623
      nm->set_scavenge_root_link(NULL);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   624
      nm->clear_on_scavenge_root_list();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   625
      return;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   626
    }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   627
    last = cur;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   628
    cur = next;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   629
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   630
  assert(false, "should have been on list");
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   631
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   632
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   633
void CodeCache::prune_scavenge_root_nmethods() {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   634
  assert_locked_or_safepoint(CodeCache_lock);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   635
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   636
  if (UseG1GC) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   637
    return;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   638
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   639
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   640
  debug_only(mark_scavenge_root_nmethods());
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   641
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   642
  nmethod* last = NULL;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   643
  nmethod* cur = scavenge_root_nmethods();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   644
  while (cur != NULL) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   645
    nmethod* next = cur->scavenge_root_link();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   646
    debug_only(cur->clear_scavenge_root_marked());
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   647
    assert(cur->scavenge_root_not_marked(), "");
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   648
    assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   649
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   650
    if (!cur->is_zombie() && !cur->is_unloaded()
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   651
        && cur->detect_scavenge_root_oops()) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   652
      // Keep it.  Advance 'last' to prevent deletion.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   653
      last = cur;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   654
    } else {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   655
      // Prune it from the list, so we don't have to look at it any more.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   656
      print_trace("prune_scavenge_root", cur);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   657
      cur->set_scavenge_root_link(NULL);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   658
      cur->clear_on_scavenge_root_list();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   659
      if (last != NULL)
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   660
            last->set_scavenge_root_link(next);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   661
      else  set_scavenge_root_nmethods(next);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   662
    }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   663
    cur = next;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   664
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   665
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   666
  // Check for stray marks.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   667
  debug_only(verify_perm_nmethods(NULL));
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   668
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   669
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   670
#ifndef PRODUCT
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   671
void CodeCache::asserted_non_scavengable_nmethods_do(CodeBlobClosure* f) {
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   672
  if (UseG1GC) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   673
    return;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   674
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   675
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   676
  // While we are here, verify the integrity of the list.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   677
  mark_scavenge_root_nmethods();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   678
  for (nmethod* cur = scavenge_root_nmethods(); cur != NULL; cur = cur->scavenge_root_link()) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   679
    assert(cur->on_scavenge_root_list(), "else shouldn't be on this list");
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   680
    cur->clear_scavenge_root_marked();
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   681
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   682
  verify_perm_nmethods(f);
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   683
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   684
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   685
// Temporarily mark nmethods that are claimed to be on the non-perm list.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   686
void CodeCache::mark_scavenge_root_nmethods() {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   687
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   688
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   689
    nmethod* nm = iter.method();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   690
    assert(nm->scavenge_root_not_marked(), "clean state");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   691
    if (nm->on_scavenge_root_list())
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   692
      nm->set_scavenge_root_marked();
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   693
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   694
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   695
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   696
// If the closure is given, run it on the unlisted nmethods.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   697
// Also make sure that the effects of mark_scavenge_root_nmethods is gone.
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   698
void CodeCache::verify_perm_nmethods(CodeBlobClosure* f_or_null) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   699
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   700
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   701
    nmethod* nm = iter.method();
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   702
    bool call_f = (f_or_null != NULL);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   703
    assert(nm->scavenge_root_not_marked(), "must be already processed");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   704
    if (nm->on_scavenge_root_list())
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   705
      call_f = false;  // don't show this one to the client
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   706
    nm->verify_scavenge_root_oops();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   707
    if (call_f)  f_or_null->do_code_blob(nm);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   708
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   709
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   710
#endif //PRODUCT
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   711
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   712
void CodeCache::verify_clean_inline_caches() {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   713
#ifdef ASSERT
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   714
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   715
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   716
    nmethod* nm = iter.method();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   717
    assert(!nm->is_unloaded(), "Tautology");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   718
    nm->verify_clean_inline_caches();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   719
    nm->verify();
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   720
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   721
#endif
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   722
}
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   723
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   724
void CodeCache::verify_icholder_relocations() {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   725
#ifdef ASSERT
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   726
  // make sure that we aren't leaking icholders
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   727
  int count = 0;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   728
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   729
    FOR_ALL_BLOBS(cb, *heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   730
      if (cb->is_nmethod()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   731
        nmethod* nm = (nmethod*)cb;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   732
        count += nm->verify_icholder_relocations();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   733
      }
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   734
    }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   735
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   736
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   737
  assert(count + InlineCacheBuffer::pending_icholder_count() + CompiledICHolder::live_not_claimed_count() ==
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   738
         CompiledICHolder::live_count(), "must agree");
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   739
#endif
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   740
}
4750
71fd601907dc 4360113: Evict nmethods when code cache gets full
kvn
parents: 3908
diff changeset
   741
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
void CodeCache::gc_prologue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
void CodeCache::gc_epilogue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   747
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   748
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   749
    nmethod* nm = iter.method();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   750
    assert(!nm->is_unloaded(), "Tautology");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   751
    if (needs_cache_clean()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   752
      nm->cleanup_inline_caches();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
    }
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   754
    DEBUG_ONLY(nm->verify());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   755
    DEBUG_ONLY(nm->verify_oop_relocations());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  set_needs_cache_clean(false);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
   758
  prune_scavenge_root_nmethods();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   759
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   760
  verify_icholder_relocations();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
8724
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8672
diff changeset
   763
void CodeCache::verify_oops() {
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8672
diff changeset
   764
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8672
diff changeset
   765
  VerifyOopClosure voc;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   766
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   767
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   768
    nmethod* nm = iter.method();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   769
    nm->oops_do(&voc);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   770
    nm->verify_oop_relocations();
8724
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8672
diff changeset
   771
  }
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8672
diff changeset
   772
}
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8672
diff changeset
   773
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   774
size_t CodeCache::capacity() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   775
  size_t cap = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   776
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   777
    cap += (*heap)->capacity();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   778
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   779
  return cap;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
26942
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   782
size_t CodeCache::unallocated_capacity(int code_blob_type) {
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   783
  CodeHeap* heap = get_code_heap(code_blob_type);
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   784
  return (heap != NULL) ? heap->unallocated_capacity() : 0;
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   785
}
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
   786
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   787
size_t CodeCache::unallocated_capacity() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   788
  size_t unallocated_cap = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   789
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   790
    unallocated_cap += (*heap)->unallocated_capacity();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   791
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   792
  return unallocated_cap;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   793
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   795
size_t CodeCache::max_capacity() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   796
  size_t max_cap = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   797
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   798
    max_cap += (*heap)->max_capacity();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   799
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   800
  return max_cap;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
17617
4e330bce1812 8012371: Adjust Tiered compile threshold according to available space in code cache
anoll
parents: 17132
diff changeset
   803
/**
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   804
 * Returns the reverse free ratio. E.g., if 25% (1/4) of the code heap
17617
4e330bce1812 8012371: Adjust Tiered compile threshold according to available space in code cache
anoll
parents: 17132
diff changeset
   805
 * is free, reverse_free_ratio() returns 4.
4e330bce1812 8012371: Adjust Tiered compile threshold according to available space in code cache
anoll
parents: 17132
diff changeset
   806
 */
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   807
double CodeCache::reverse_free_ratio(int code_blob_type) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   808
  CodeHeap* heap = get_code_heap(code_blob_type);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   809
  if (heap == NULL) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   810
    return 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   811
  }
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   812
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   813
  double unallocated_capacity = MAX2((double)heap->unallocated_capacity(), 1.0); // Avoid division by 0;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   814
  double max_capacity = (double)heap->max_capacity();
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   815
  double result = max_capacity / unallocated_capacity;
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   816
  assert (max_capacity >= unallocated_capacity, "Must be");
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   817
  assert (result >= 1.0, err_msg_res("reverse_free_ratio must be at least 1. It is %f", result));
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 27410
diff changeset
   818
  return result;
17617
4e330bce1812 8012371: Adjust Tiered compile threshold according to available space in code cache
anoll
parents: 17132
diff changeset
   819
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   821
size_t CodeCache::bytes_allocated_in_freelists() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   822
  size_t allocated_bytes = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   823
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   824
    allocated_bytes += (*heap)->allocated_in_freelist();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   825
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   826
  return allocated_bytes;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   827
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   828
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   829
int CodeCache::allocated_segments() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   830
  int number_of_segments = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   831
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   832
    number_of_segments += (*heap)->allocated_segments();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   833
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   834
  return number_of_segments;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   835
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   836
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   837
size_t CodeCache::freelists_length() {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   838
  size_t length = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   839
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   840
    length += (*heap)->freelist_length();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   841
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   842
  return length;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   843
}
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   844
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
void icache_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
void CodeCache::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  assert(CodeCacheSegmentSize >= (uintx)CodeEntryAlignment, "CodeCacheSegmentSize must be large enough to align entry points");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
#ifdef COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  assert(CodeCacheSegmentSize >= (uintx)OptoLoopAlignment,  "CodeCacheSegmentSize must be large enough to align inner loops");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  assert(CodeCacheSegmentSize >= sizeof(jdouble),    "CodeCacheSegmentSize must be large enough to align constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  // This was originally just a check of the alignment, causing failure, instead, round
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  // the code cache to the page size.  In particular, Solaris is moving to a larger
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  // default page size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  CodeCacheExpansionSize = round_to(CodeCacheExpansionSize, os::vm_page_size());
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   857
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   858
  if (SegmentedCodeCache) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   859
    // Use multiple code heaps
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   860
    initialize_heaps();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   861
  } else {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   862
    // Use a single code heap
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   863
    ReservedCodeSpace rs = reserve_heap_memory(ReservedCodeCacheSize);
28730
106944a21769 8064940: JMH javac performance regressions on solaris-sparcv9 in 9-b34
thartmann
parents: 28631
diff changeset
   864
    add_heap(rs, "CodeCache", CodeBlobType::All);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  // Initialize ICache flush mechanism
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // This service is needed for os::register_code_area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  icache_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  // Give OS a chance to register generated code area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  // This is used on Windows 64 bit platforms to register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  // Structured Exception Handlers for our generated code.
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   874
  os::register_code_area((char*)low_bound(), (char*)high_bound());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
void codeCache_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  CodeCache::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
//------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
int CodeCache::number_of_nmethods_with_dependencies() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  return _number_of_nmethods_with_dependencies;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
void CodeCache::clear_inline_caches() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   889
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   890
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   891
    iter.method()->clear_inline_caches();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
22506
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   895
// Keeps track of time spent for checking dependencies
22921
ee35d5c0b1dc 8034839: jvm hangs with gc/gctests/LoadUnloadGC test
anoll
parents: 22506
diff changeset
   896
NOT_PRODUCT(static elapsedTimer dependentCheckTime;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
int CodeCache::mark_for_deoptimization(DepChange& changes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  int number_of_marked_CodeBlobs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  // search the hierarchy looking for nmethods which are affected by the loading of this class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  // then search the interfaces this class implements looking for nmethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  // which might be dependent of the fact that an interface only had one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  // implementor.
22506
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   907
  // nmethod::check_all_dependencies works only correctly, if no safepoint
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   908
  // can happen
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   909
  No_Safepoint_Verifier nsv;
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   910
  for (DepChange::ContextStream str(changes, nsv); str.next(); ) {
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   911
    Klass* d = str.klass();
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   912
    number_of_marked_CodeBlobs += InstanceKlass::cast(d)->mark_dependent_nmethods(changes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
#ifndef PRODUCT
22506
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   916
  if (VerifyDependencies) {
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   917
    // Object pointers are used as unique identifiers for dependency arguments. This
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   918
    // is only possible if no safepoint, i.e., GC occurs during the verification code.
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   919
    dependentCheckTime.start();
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   920
    nmethod::check_all_dependencies(changes);
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   921
    dependentCheckTime.stop();
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   922
  }
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
   923
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  return number_of_marked_CodeBlobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
#ifdef HOTSWAP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
int CodeCache::mark_for_evol_deoptimization(instanceKlassHandle dependee) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  int number_of_marked_CodeBlobs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  // Deoptimize all methods of the evolving class itself
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   935
  Array<Method*>* old_methods = dependee->methods();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  for (int i = 0; i < old_methods->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    ResourceMark rm;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   938
    Method* old_method = old_methods->at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    nmethod *nm = old_method->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    if (nm != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
      nm->mark_for_deoptimization();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
      number_of_marked_CodeBlobs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   946
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   947
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   948
    nmethod* nm = iter.method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    if (nm->is_marked_for_deoptimization()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
      // ...Already marked in the previous pass; don't count it again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    } else if (nm->is_evol_dependent_on(dependee())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
      nm->mark_for_deoptimization();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
      number_of_marked_CodeBlobs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    } else  {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   956
      // flush caches in case they refer to a redefined Method*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
      nm->clear_inline_caches();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  return number_of_marked_CodeBlobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
#endif // HOTSWAP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
// Deoptimize all methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
void CodeCache::mark_all_nmethods_for_deoptimization() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   969
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   970
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   971
    nmethod* nm = iter.method();
26580
8cca7fbe77b8 8056154: JVM crash with EXCEPTION_ACCESS_VIOLATION when there are many threads running
iveresov
parents: 25492
diff changeset
   972
    if (!nm->method()->is_method_handle_intrinsic()) {
8cca7fbe77b8 8056154: JVM crash with EXCEPTION_ACCESS_VIOLATION when there are many threads running
iveresov
parents: 25492
diff changeset
   973
      nm->mark_for_deoptimization();
8cca7fbe77b8 8056154: JVM crash with EXCEPTION_ACCESS_VIOLATION when there are many threads running
iveresov
parents: 25492
diff changeset
   974
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   978
int CodeCache::mark_for_deoptimization(Method* dependee) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  int number_of_marked_CodeBlobs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   982
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   983
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   984
    nmethod* nm = iter.method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    if (nm->is_dependent_on_method(dependee)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
      ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
      nm->mark_for_deoptimization();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
      number_of_marked_CodeBlobs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  return number_of_marked_CodeBlobs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
void CodeCache::make_marked_nmethods_zombies() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   997
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   998
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
   999
    nmethod* nm = iter.method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
    if (nm->is_marked_for_deoptimization()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
      // If the nmethod has already been made non-entrant and it can be converted
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
      // then zombie it now. Otherwise make it non-entrant and it will eventually
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
      // be zombied when it is no longer seen on the stack. Note that the nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
      // might be "entrant" and not on the stack and so could be zombied immediately
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      // but we can't tell because we don't track it on stack until it becomes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
      // non-entrant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
      if (nm->is_not_entrant() && nm->can_not_entrant_be_converted()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
        nm->make_zombie();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
        nm->make_not_entrant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
void CodeCache::make_marked_nmethods_not_entrant() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  assert_locked_or_safepoint(CodeCache_lock);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1020
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1021
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1022
    nmethod* nm = iter.method();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
    if (nm->is_marked_for_deoptimization()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
      nm->make_not_entrant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1029
// Flushes compiled methods dependent on dependee.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1030
void CodeCache::flush_dependents_on(instanceKlassHandle dependee) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1031
  assert_lock_strong(Compile_lock);
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1032
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1033
  if (number_of_nmethods_with_dependencies() == 0) return;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1034
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1035
  // CodeCache can only be updated by a thread_in_VM and they will all be
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1036
  // stopped during the safepoint so CodeCache will be safe to update without
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1037
  // holding the CodeCache_lock.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1038
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1039
  KlassDepChange changes(dependee);
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1040
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1041
  // Compute the dependent nmethods
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1042
  if (mark_for_deoptimization(changes) > 0) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1043
    // At least one nmethod has been marked for deoptimization
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1044
    VM_Deoptimize op;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1045
    VMThread::execute(&op);
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1046
  }
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1047
}
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1048
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1049
// Flushes compiled methods dependent on a particular CallSite
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1050
// instance when its target is different than the given MethodHandle.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1051
void CodeCache::flush_dependents_on(Handle call_site, Handle method_handle) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1052
  assert_lock_strong(Compile_lock);
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1053
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1054
  if (number_of_nmethods_with_dependencies() == 0) return;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1055
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1056
  // CodeCache can only be updated by a thread_in_VM and they will all be
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1057
  // stopped during the safepoint so CodeCache will be safe to update without
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1058
  // holding the CodeCache_lock.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1059
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1060
  CallSiteDepChange changes(call_site(), method_handle());
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1061
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1062
  // Compute the dependent nmethods that have a reference to a
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1063
  // CallSite object.  We use InstanceKlass::mark_dependent_nmethod
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1064
  // directly instead of CodeCache::mark_for_deoptimization because we
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1065
  // want dependents on the call site class only not all classes in
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1066
  // the ContextStream.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1067
  int marked = 0;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1068
  {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1069
    MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
30296
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 29358
diff changeset
  1070
    InstanceKlass* ctxk = MethodHandles::get_call_site_context(call_site());
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 29358
diff changeset
  1071
    if (ctxk == NULL) {
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 29358
diff changeset
  1072
      return; // No dependencies to invalidate yet.
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 29358
diff changeset
  1073
    }
95baefac8485 8057967: CallSite dependency tracking scales devastatingly poorly
vlivanov
parents: 29358
diff changeset
  1074
    marked = ctxk->mark_dependent_nmethods(changes);
28374
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1075
  }
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1076
  if (marked > 0) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1077
    // At least one nmethod has been marked for deoptimization
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1078
    VM_Deoptimize op;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1079
    VMThread::execute(&op);
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1080
  }
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1081
}
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1082
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1083
#ifdef HOTSWAP
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1084
// Flushes compiled methods dependent on dependee in the evolutionary sense
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1085
void CodeCache::flush_evol_dependents_on(instanceKlassHandle ev_k_h) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1086
  // --- Compile_lock is not held. However we are at a safepoint.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1087
  assert_locked_or_safepoint(Compile_lock);
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1088
  if (number_of_nmethods_with_dependencies() == 0) return;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1089
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1090
  // CodeCache can only be updated by a thread_in_VM and they will all be
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1091
  // stopped during the safepoint so CodeCache will be safe to update without
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1092
  // holding the CodeCache_lock.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1093
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1094
  // Compute the dependent nmethods
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1095
  if (mark_for_evol_deoptimization(ev_k_h) > 0) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1096
    // At least one nmethod has been marked for deoptimization
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1097
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1098
    // All this already happens inside a VM_Operation, so we'll do all the work here.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1099
    // Stuff copied from VM_Deoptimize and modified slightly.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1100
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1101
    // We do not want any GCs to happen while we are in the middle of this VM operation
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1102
    ResourceMark rm;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1103
    DeoptimizationMarker dm;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1104
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1105
    // Deoptimize all activations depending on marked nmethods
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1106
    Deoptimization::deoptimize_dependents();
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1107
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1108
    // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1109
    make_marked_nmethods_not_entrant();
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1110
  }
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1111
}
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1112
#endif // HOTSWAP
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1113
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1114
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1115
// Flushes compiled methods dependent on dependee
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1116
void CodeCache::flush_dependents_on_method(methodHandle m_h) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1117
  // --- Compile_lock is not held. However we are at a safepoint.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1118
  assert_locked_or_safepoint(Compile_lock);
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1119
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1120
  // CodeCache can only be updated by a thread_in_VM and they will all be
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1121
  // stopped dring the safepoint so CodeCache will be safe to update without
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1122
  // holding the CodeCache_lock.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1123
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1124
  // Compute the dependent nmethods
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1125
  if (mark_for_deoptimization(m_h()) > 0) {
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1126
    // At least one nmethod has been marked for deoptimization
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1127
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1128
    // All this already happens inside a VM_Operation, so we'll do all the work here.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1129
    // Stuff copied from VM_Deoptimize and modified slightly.
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1130
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1131
    // We do not want any GCs to happen while we are in the middle of this VM operation
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1132
    ResourceMark rm;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1133
    DeoptimizationMarker dm;
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1134
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1135
    // Deoptimize all activations depending on marked nmethods
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1136
    Deoptimization::deoptimize_dependents();
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1137
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1138
    // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1139
    make_marked_nmethods_not_entrant();
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1140
  }
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1141
}
0558e321c027 8067836: The Universe::flush_foo methods belong in CodeCache.
coleenp
parents: 27880
diff changeset
  1142
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
void CodeCache::verify() {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1144
  assert_locked_or_safepoint(CodeCache_lock);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1145
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1146
    (*heap)->verify();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1147
    FOR_ALL_BLOBS(cb, *heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1148
      if (cb->is_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1149
        cb->verify();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1150
      }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1151
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1155
// A CodeHeap is full. Print out warning and report event.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1156
void CodeCache::report_codemem_full(int code_blob_type, bool print) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1157
  // Get nmethod heap for the given CodeBlobType and build CodeCacheFull event
26942
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
  1158
  CodeHeap* heap = get_code_heap(code_blob_type);
fa5ea7ff078d 8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents: 26919
diff changeset
  1159
  assert(heap != NULL, "heap is null");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1160
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1161
  if (!heap->was_full() || print) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1162
    // Not yet reported for this heap, report
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1163
    heap->report_full();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1164
    if (SegmentedCodeCache) {
27410
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
  1165
      warning("%s is full. Compiler has been disabled.", get_code_heap_name(code_blob_type));
dd80df7cfa2b 8060196: 'CodeHeap is full' warning suggests to increase wrong code heap size
thartmann
parents: 27015
diff changeset
  1166
      warning("Try increasing the code heap size using -XX:%s=", get_code_heap_flag_name(code_blob_type));
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1167
    } else {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1168
      warning("CodeCache is full. Compiler has been disabled.");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1169
      warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1170
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1171
    ResourceMark rm;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1172
    stringStream s;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1173
    // Dump code cache  into a buffer before locking the tty,
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1174
    {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1175
      MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1176
      print_summary(&s);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1177
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1178
    ttyLocker ttyl;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1179
    tty->print("%s", s.as_string());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1180
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1181
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1182
  _codemem_full_count++;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1183
  EventCodeCacheFull event;
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1184
  if (event.should_commit()) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1185
    event.set_codeBlobType((u1)code_blob_type);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1186
    event.set_startAddress((u8)heap->low_boundary());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1187
    event.set_commitedTopAddress((u8)heap->high());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1188
    event.set_reservedTopAddress((u8)heap->high_boundary());
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1189
    event.set_entryCount(nof_blobs());
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1190
    event.set_methodCount(nof_nmethods());
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1191
    event.set_adaptorCount(nof_adapters());
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1192
    event.set_unallocatedCapacity(heap->unallocated_capacity()/K);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1193
    event.set_fullCount(_codemem_full_count);
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1194
    event.commit();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1195
  }
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1196
}
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17617
diff changeset
  1197
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1198
void CodeCache::print_memory_overhead() {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1199
  size_t wasted_bytes = 0;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1200
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1201
      CodeHeap* curr_heap = *heap;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1202
      for (CodeBlob* cb = (CodeBlob*)curr_heap->first(); cb != NULL; cb = (CodeBlob*)curr_heap->next(cb)) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1203
        HeapBlock* heap_block = ((HeapBlock*)cb) - 1;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1204
        wasted_bytes += heap_block->length() * CodeCacheSegmentSize - cb->size();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1205
      }
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1206
  }
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1207
  // Print bytes that are allocated in the freelist
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1208
  ttyLocker ttl;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1209
  tty->print_cr("Number of elements in freelist: " SSIZE_FORMAT,       freelists_length());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1210
  tty->print_cr("Allocated in freelist:          " SSIZE_FORMAT "kB",  bytes_allocated_in_freelists()/K);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23214
diff changeset
  1211
  tty->print_cr("Unused bytes in CodeBlobs:      " SSIZE_FORMAT "kB",  (wasted_bytes/K));
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23214
diff changeset
  1212
  tty->print_cr("Segment map size:               " SSIZE_FORMAT "kB",  allocated_segments()/K); // 1 byte per segment
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1213
}
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1214
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
//------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
// Non-product version
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
  1220
void CodeCache::print_trace(const char* event, CodeBlob* cb, int size) {
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
  1221
  if (PrintCodeCache2) {  // Need to add a new flag
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
  1222
    ResourceMark rm;
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
  1223
    if (size == 0)  size = cb->size();
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23214
diff changeset
  1224
    tty->print_cr("CodeCache %s:  addr: " INTPTR_FORMAT ", size: 0x%x", event, p2i(cb), size);
3908
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
  1225
  }
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
  1226
}
24b55ad4c228 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 1
diff changeset
  1227
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
void CodeCache::print_internals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
  int nmethodCount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
  int runtimeStubCount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  int adapterCount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
  int deoptimizationStubCount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
  int uncommonTrapStubCount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
  int bufferBlobCount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
  int total = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  int nmethodAlive = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
  int nmethodNotEntrant = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  int nmethodZombie = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
  int nmethodUnloaded = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
  int nmethodJava = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  int nmethodNative = 0;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1242
  int max_nm_size = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1245
  int i = 0;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1246
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1247
    if (SegmentedCodeCache && Verbose) {
26918
4e1761669426 8059137: MemoryPoolMXBeans for different code heaps should contain 'Code heap' in their names
thartmann
parents: 26809
diff changeset
  1248
      tty->print_cr("-- %s --", (*heap)->name());
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1249
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1250
    FOR_ALL_BLOBS(cb, *heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1251
      total++;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1252
      if (cb->is_nmethod()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1253
        nmethod* nm = (nmethod*)cb;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1255
        if (Verbose && nm->method() != NULL) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1256
          ResourceMark rm;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1257
          char *method_name = nm->method()->name_and_sig_as_C_string();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1258
          tty->print("%s", method_name);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1259
          if(nm->is_alive()) { tty->print_cr(" alive"); }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1260
          if(nm->is_not_entrant()) { tty->print_cr(" not-entrant"); }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1261
          if(nm->is_zombie()) { tty->print_cr(" zombie"); }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1262
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1264
        nmethodCount++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1266
        if(nm->is_alive()) { nmethodAlive++; }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1267
        if(nm->is_not_entrant()) { nmethodNotEntrant++; }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1268
        if(nm->is_zombie()) { nmethodZombie++; }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1269
        if(nm->is_unloaded()) { nmethodUnloaded++; }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1270
        if(nm->method() != NULL && nm->is_native_method()) { nmethodNative++; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1272
        if(nm->method() != NULL && nm->is_java_method()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1273
          nmethodJava++;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1274
          max_nm_size = MAX2(max_nm_size, nm->size());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1275
        }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1276
      } else if (cb->is_runtime_stub()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1277
        runtimeStubCount++;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1278
      } else if (cb->is_deoptimization_stub()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1279
        deoptimizationStubCount++;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1280
      } else if (cb->is_uncommon_trap_stub()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1281
        uncommonTrapStubCount++;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1282
      } else if (cb->is_adapter_blob()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1283
        adapterCount++;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1284
      } else if (cb->is_buffer_blob()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1285
        bufferBlobCount++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  int bucketSize = 512;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1291
  int bucketLimit = max_nm_size / bucketSize + 1;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9630
diff changeset
  1292
  int *buckets = NEW_C_HEAP_ARRAY(int, bucketLimit, mtCode);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1293
  memset(buckets, 0, sizeof(int) * bucketLimit);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1295
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1296
  while(iter.next()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1297
    nmethod* nm = iter.method();
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1298
    if(nm->method() != NULL && nm->is_java_method()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1299
      buckets[nm->size() / bucketSize]++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
  }
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1302
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
  tty->print_cr("Code Cache Entries (total of %d)",total);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  tty->print_cr("-------------------------------------------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  tty->print_cr("nmethods: %d",nmethodCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  tty->print_cr("\talive: %d",nmethodAlive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
  tty->print_cr("\tnot_entrant: %d",nmethodNotEntrant);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  tty->print_cr("\tzombie: %d",nmethodZombie);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
  tty->print_cr("\tunloaded: %d",nmethodUnloaded);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
  tty->print_cr("\tjava: %d",nmethodJava);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  tty->print_cr("\tnative: %d",nmethodNative);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  tty->print_cr("runtime_stubs: %d",runtimeStubCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
  tty->print_cr("adapters: %d",adapterCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
  tty->print_cr("buffer blobs: %d",bufferBlobCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
  tty->print_cr("deoptimization_stubs: %d",deoptimizationStubCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
  tty->print_cr("uncommon_traps: %d",uncommonTrapStubCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
  tty->print_cr("\nnmethod size distribution (non-zombie java)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
  tty->print_cr("-------------------------------------------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
  for(int i=0; i<bucketLimit; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
    if(buckets[i] != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
      tty->print("%d - %d bytes",i*bucketSize,(i+1)*bucketSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
      tty->fill_to(40);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
      tty->print_cr("%d",buckets[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 27642
diff changeset
  1328
  FREE_C_HEAP_ARRAY(int, buckets);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22921
diff changeset
  1329
  print_memory_overhead();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1332
#endif // !PRODUCT
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1333
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
void CodeCache::print() {
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1335
  print_summary(tty);
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1336
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1337
#ifndef PRODUCT
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1338
  if (!Verbose) return;
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1339
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
  CodeBlob_sizes live;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
  CodeBlob_sizes dead;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1343
  FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1344
    FOR_ALL_BLOBS(cb, *heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1345
      if (!cb->is_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1346
        dead.add(cb);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1347
      } else {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1348
        live.add(cb);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1349
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
  tty->print_cr("CodeCache:");
22506
0759c126204d 7194669: CodeCache::mark_for_deoptimization should avoid verifying dependencies multiple times
anoll
parents: 20290
diff changeset
  1354
  tty->print_cr("nmethod dependency checking time %fs", dependentCheckTime.seconds());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  if (!live.is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
    live.print("live");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  if (!dead.is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
    dead.print("dead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1363
  if (WizardMode) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
     // print the oop_map usage
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
    int code_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
    int number_of_blobs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
    int number_of_oop_maps = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
    int map_size = 0;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1369
    FOR_ALL_HEAPS(heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1370
      FOR_ALL_BLOBS(cb, *heap) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1371
        if (cb->is_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1372
          number_of_blobs++;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1373
          code_size += cb->code_size();
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 30296
diff changeset
  1374
          ImmutableOopMapSet* set = cb->oop_maps();
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1375
          if (set != NULL) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 30296
diff changeset
  1376
            number_of_oop_maps += set->count();
30628
3c15b4a3bf4d 8079797: assert(index >= 0 && index < _count) failed: check
rbackman
parents: 30590
diff changeset
  1377
            map_size           += set->nr_of_bytes();
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1378
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
    tty->print_cr("OopMaps");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
    tty->print_cr("  #blobs    = %d", number_of_blobs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
    tty->print_cr("  code size = %d", code_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
    tty->print_cr("  #oop_maps = %d", number_of_oop_maps);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
    tty->print_cr("  map size  = %d", map_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1389
#endif // !PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1392
void CodeCache::print_summary(outputStream* st, bool detailed) {
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1393
  FOR_ALL_HEAPS(heap_iterator) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1394
    CodeHeap* heap = (*heap_iterator);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1395
    size_t total = (heap->high_boundary() - heap->low_boundary());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1396
    if (SegmentedCodeCache) {
26918
4e1761669426 8059137: MemoryPoolMXBeans for different code heaps should contain 'Code heap' in their names
thartmann
parents: 26809
diff changeset
  1397
      st->print("%s:", heap->name());
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1398
    } else {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26918
diff changeset
  1399
      st->print("CodeCache:");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1400
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1401
    st->print_cr(" size=" SIZE_FORMAT "Kb used=" SIZE_FORMAT
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1402
                 "Kb max_used=" SIZE_FORMAT "Kb free=" SIZE_FORMAT "Kb",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1403
                 total/K, (total - heap->unallocated_capacity())/K,
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1404
                 heap->max_allocated_capacity()/K, heap->unallocated_capacity()/K);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1405
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1406
    if (detailed) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1407
      st->print_cr(" bounds [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT "]",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1408
                   p2i(heap->low_boundary()),
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1409
                   p2i(heap->high()),
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1410
                   p2i(heap->high_boundary()));
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1411
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1412
  }
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
  1413
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1414
  if (detailed) {
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1415
    st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1416
                       " adapters=" UINT32_FORMAT,
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1417
                       nof_blobs(), nof_nmethods(), nof_adapters());
15201
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1418
    st->print_cr(" compilation: %s", CompileBroker::should_compile_new_jobs() ?
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1419
                 "enabled" : Arguments::mode() == Arguments::_int ?
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1420
                 "disabled (interpreter mode)" :
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1421
                 "disabled (not enough contiguous free space left)");
f3d755b11424 8005204: Code Cache Reduction: command line options implementation
vladidan
parents: 13878
diff changeset
  1422
  }
7108
4f87b92f3060 6970683: improvements to hs_err output
never
parents: 6418
diff changeset
  1423
}
8672
26a427ab6f32 7025742: Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
kvn
parents: 7715
diff changeset
  1424
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1425
void CodeCache::print_codelist(outputStream* st) {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1426
  assert_locked_or_safepoint(CodeCache_lock);
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1427
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1428
  NMethodIterator iter;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1429
  while(iter.next_alive()) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1430
    nmethod* nm = iter.method();
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1431
    ResourceMark rm;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1432
    char *method_name = nm->method()->name_and_sig_as_C_string();
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1433
    st->print_cr("%d %d %s ["INTPTR_FORMAT", "INTPTR_FORMAT" - "INTPTR_FORMAT"]",
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1434
                 nm->compile_id(), nm->comp_level(), method_name, (intptr_t)nm->header_begin(),
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 26587
diff changeset
  1435
                 (intptr_t)nm->code_begin(), (intptr_t)nm->code_end());
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1436
  }
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1437
}
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1438
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1439
void CodeCache::print_layout(outputStream* st) {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1440
  assert_locked_or_safepoint(CodeCache_lock);
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1441
  ResourceMark rm;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1442
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1443
  print_summary(st, true);
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1444
}
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents: 26580
diff changeset
  1445
8672
26a427ab6f32 7025742: Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
kvn
parents: 7715
diff changeset
  1446
void CodeCache::log_state(outputStream* st) {
26a427ab6f32 7025742: Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
kvn
parents: 7715
diff changeset
  1447
  st->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'"
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 15201
diff changeset
  1448
            " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
8672
26a427ab6f32 7025742: Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
kvn
parents: 7715
diff changeset
  1449
            nof_blobs(), nof_nmethods(), nof_adapters(),
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 15201
diff changeset
  1450
            unallocated_capacity());
8672
26a427ab6f32 7025742: Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
kvn
parents: 7715
diff changeset
  1451
}