hotspot/src/share/vm/memory/heap.cpp
author stefank
Tue, 04 Jul 2017 15:58:10 +0200
changeset 46619 a3919f5e8d2b
parent 43945 e7f2e49d2274
child 46625 edefffab74e2
permissions -rw-r--r--
8178499: Remove _ptr_ and _size_ infixes from align functions Reviewed-by: rehn, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28636
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: 4493
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4493
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: 4493
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/heap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/os.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
    29
#include "services/memTracker.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
size_t CodeHeap::header_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  return sizeof(HeapBlock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Implementation of Heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
    38
CodeHeap::CodeHeap(const char* name, const int code_blob_type)
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
    39
  : _code_blob_type(code_blob_type) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
    40
  _name                         = name;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  _number_of_committed_segments = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _number_of_reserved_segments  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _segment_size                 = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _log2_segment_size            = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _next_segment                 = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _freelist                     = NULL;
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
    47
  _freelist_segments            = 0;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
    48
  _freelist_length              = 0;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
    49
  _max_allocated_capacity       = 0;
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 29580
diff changeset
    50
  _blob_count                   = 0;
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 29580
diff changeset
    51
  _nmethod_count                = 0;
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 29580
diff changeset
    52
  _adapter_count                = 0;
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 29580
diff changeset
    53
  _full_count                   = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
void CodeHeap::mark_segmap_as_free(size_t beg, size_t end) {
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28636
diff changeset
    58
  assert(              beg <  _number_of_committed_segments, "interval begin out of bounds");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  assert(beg <  end && end <= _number_of_committed_segments, "interval end   out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // setup _segmap pointers for faster indexing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  address p = (address)_segmap.low() + beg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  address q = (address)_segmap.low() + end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // initialize interval
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
    64
  while (p < q) *p++ = free_sentinel;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
void CodeHeap::mark_segmap_as_used(size_t beg, size_t end) {
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 28636
diff changeset
    69
  assert(              beg <  _number_of_committed_segments, "interval begin out of bounds");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  assert(beg <  end && end <= _number_of_committed_segments, "interval end   out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // setup _segmap pointers for faster indexing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  address p = (address)_segmap.low() + beg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  address q = (address)_segmap.low() + end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // initialize interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  while (p < q) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    *p++ = i++;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
    78
    if (i == free_sentinel) i = 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
static size_t align_to_page_size(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  const size_t alignment = (size_t)os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  assert(is_power_of_2(alignment), "no kidding ???");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  return (size + alignment - 1) & ~(alignment - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
void CodeHeap::on_code_mapping(char* base, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
#ifdef LINUX
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  extern void linux_wrap_code(char* base, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  linux_wrap_code(base, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
    98
bool CodeHeap::reserve(ReservedSpace rs, size_t committed_size, size_t segment_size) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
    99
  assert(rs.size() >= committed_size, "reserved < committed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  assert(segment_size >= sizeof(FreeBlock), "segment size is too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  assert(is_power_of_2(segment_size), "segment_size must be a power of 2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _segment_size      = segment_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _log2_segment_size = exact_log2(segment_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Reserve and initialize space for _memory.
26700
8107d0778244 8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents: 25366
diff changeset
   107
  size_t page_size = os::vm_page_size();
8107d0778244 8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents: 25366
diff changeset
   108
  if (os::can_execute_large_page_memory()) {
8107d0778244 8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents: 25366
diff changeset
   109
    const size_t min_pages = 8;
28631
a56cae1b428d 8066875: VirtualSpace does not use large pages
ehelin
parents: 27420
diff changeset
   110
    page_size = MIN2(os::page_size_for_region_aligned(committed_size, min_pages),
a56cae1b428d 8066875: VirtualSpace does not use large pages
ehelin
parents: 27420
diff changeset
   111
                     os::page_size_for_region_aligned(rs.size(), min_pages));
26700
8107d0778244 8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents: 25366
diff changeset
   112
  }
8107d0778244 8049864: TestParallelHeapSizeFlags fails with unexpected heap size
ehelin
parents: 25366
diff changeset
   113
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  const size_t granularity = os::vm_allocation_granularity();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 43945
diff changeset
   115
  const size_t c_size = align_up(committed_size, page_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
   117
  os::trace_page_sizes(_name, committed_size, rs.size(), page_size,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
                       rs.base(), rs.size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  if (!_memory.initialize(rs, c_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  on_code_mapping(_memory.low(), _memory.committed_size());
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   124
  _number_of_committed_segments = size_to_segments(_memory.committed_size());
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   125
  _number_of_reserved_segments  = size_to_segments(_memory.reserved_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking");
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 17016
diff changeset
   127
  const size_t reserved_segments_alignment = MAX2((size_t)os::vm_page_size(), granularity);
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 43945
diff changeset
   128
  const size_t reserved_segments_size = align_up(_number_of_reserved_segments, reserved_segments_alignment);
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 17016
diff changeset
   129
  const size_t committed_segments_size = align_to_page_size(_number_of_committed_segments);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // reserve space for _segmap
19319
0ad35be0733a 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 17016
diff changeset
   132
  if (!_segmap.initialize(reserved_segments_size, committed_segments_size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   135
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   136
  MemTracker::record_virtual_memory_type((address)_segmap.low_boundary(), mtCode);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   137
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "could not commit  enough space for segment map");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  assert(_segmap.reserved_size()  >= (size_t) _number_of_reserved_segments , "could not reserve enough space for segment map");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  assert(_segmap.reserved_size()  >= _segmap.committed_size()     , "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // initialize remaining instance variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
bool CodeHeap::expand_by(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // expand _memory space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  size_t dm = align_to_page_size(_memory.committed_size() + size) - _memory.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  if (dm > 0) {
35590
39a11b5f4283 8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents: 34158
diff changeset
   152
    // Use at least the available uncommitted space if 'size' is larger
39a11b5f4283 8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents: 34158
diff changeset
   153
    if (_memory.uncommitted_size() != 0 && dm > _memory.uncommitted_size()) {
39a11b5f4283 8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents: 34158
diff changeset
   154
      dm = _memory.uncommitted_size();
39a11b5f4283 8065334: CodeHeap expansion fails although there is uncommitted memory
thartmann
parents: 34158
diff changeset
   155
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    char* base = _memory.low() + _memory.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (!_memory.expand_by(dm)) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    on_code_mapping(base, dm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    size_t i = _number_of_committed_segments;
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   160
    _number_of_committed_segments = size_to_segments(_memory.committed_size());
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   161
    assert(_number_of_reserved_segments == size_to_segments(_memory.reserved_size()), "number of reserved segments should not change");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    // expand _segmap space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    size_t ds = align_to_page_size(_number_of_committed_segments) - _segmap.committed_size();
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   165
    if ((ds > 0) && !_segmap.expand_by(ds)) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   166
      return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    // initialize additional segmap entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    mark_segmap_as_free(i, _number_of_committed_segments);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
void CodeHeap::clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  _next_segment = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  mark_segmap_as_free(0, _number_of_committed_segments);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26809
diff changeset
   181
void* CodeHeap::allocate(size_t instance_size) {
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   182
  size_t number_of_segments = size_to_segments(instance_size + header_size());
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   183
  assert(segments_to_size(number_of_segments) >= sizeof(FreeBlock), "not enough room for FreeList");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 19319
diff changeset
   185
  // First check if we can satisfy request from freelist
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   186
  NOT_PRODUCT(verify());
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26809
diff changeset
   187
  HeapBlock* block = search_freelist(number_of_segments);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   188
  NOT_PRODUCT(verify());
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   189
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (block != NULL) {
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   191
    assert(block->length() >= number_of_segments && block->length() < number_of_segments + CodeCacheMinBlockLength, "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    assert(!block->free(), "must be marked free");
43945
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   193
    guarantee((char*) block >= _memory.low_boundary() && (char*) block < _memory.high(),
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   194
              "The newly allocated block " INTPTR_FORMAT " is not within the heap "
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   195
              "starting with "  INTPTR_FORMAT " and ending with "  INTPTR_FORMAT,
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   196
              p2i(block), p2i(_memory.low_boundary()), p2i(_memory.high()));
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   197
    DEBUG_ONLY(memset((void*)block->allocated_space(), badCodeHeapNewVal, instance_size));
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
   198
    _max_allocated_capacity = MAX2(_max_allocated_capacity, allocated_capacity());
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 29580
diff changeset
   199
    _blob_count++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    return block->allocated_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   203
  // Ensure minimum size for allocation to the heap.
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   204
  number_of_segments = MAX2((int)CodeCacheMinBlockLength, (int)number_of_segments);
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   205
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   206
  if (_next_segment + number_of_segments <= _number_of_committed_segments) {
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   207
    mark_segmap_as_used(_next_segment, _next_segment + number_of_segments);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    HeapBlock* b =  block_at(_next_segment);
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   209
    b->initialize(number_of_segments);
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   210
    _next_segment += number_of_segments;
43945
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   211
    guarantee((char*) b >= _memory.low_boundary() && (char*) block < _memory.high(),
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   212
              "The newly allocated block " INTPTR_FORMAT " is not within the heap "
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   213
              "starting with "  INTPTR_FORMAT " and ending with " INTPTR_FORMAT,
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   214
              p2i(b), p2i(_memory.low_boundary()), p2i(_memory.high()));
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   215
    DEBUG_ONLY(memset((void *)b->allocated_space(), badCodeHeapNewVal, instance_size));
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents: 25366
diff changeset
   216
    _max_allocated_capacity = MAX2(_max_allocated_capacity, allocated_capacity());
34158
1f8d643b02d5 8067378: Add segmented code heaps info into jfr events: vm/code_cache/stats and vm/code_cache/config
thartmann
parents: 29580
diff changeset
   217
    _blob_count++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    return b->allocated_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
void CodeHeap::deallocate(void* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  assert(p == find_start(p), "illegal deallocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // Find start of HeapBlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  HeapBlock* b = (((HeapBlock *)p) - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  assert(b->allocated_space() == p, "sanity check");
43945
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   230
  guarantee((char*) b >= _memory.low_boundary() && (char*) b < _memory.high(),
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   231
            "The block to be deallocated " INTPTR_FORMAT " is not within the heap "
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   232
            "starting with "  INTPTR_FORMAT " and ending with " INTPTR_FORMAT,
e7f2e49d2274 8173151: Code heap corruption due to incorrect inclusion test
zmajo
parents: 42650
diff changeset
   233
            p2i(b), p2i(_memory.low_boundary()), p2i(_memory.high()));
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   234
  DEBUG_ONLY(memset((void *)b->allocated_space(), badCodeHeapFreeVal,
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   235
             segments_to_size(b->length()) - sizeof(HeapBlock)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  add_to_freelist(b);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   237
  NOT_PRODUCT(verify());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   240
/**
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   241
 * Uses segment map to find the the start (header) of a nmethod. This works as follows:
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   242
 * The memory of the code cache is divided into 'segments'. The size of a segment is
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   243
 * determined by -XX:CodeCacheSegmentSize=XX. Allocation in the code cache can only
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   244
 * happen at segment boundaries. A pointer in the code cache can be mapped to a segment
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   245
 * by calling segment_for(addr). Each time memory is requested from the code cache,
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   246
 * the segmap is updated accordingly. See the following example, which illustrates the
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   247
 * state of code cache and the segment map: (seg -> segment, nm ->nmethod)
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   248
 *
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   249
 *          code cache          segmap
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   250
 *         -----------        ---------
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   251
 * seg 1   | nm 1    |   ->   | 0     |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   252
 * seg 2   | nm 1    |   ->   | 1     |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   253
 * ...     | nm 1    |   ->   | ..    |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   254
 * seg m   | nm 2    |   ->   | 0     |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   255
 * seg m+1 | nm 2    |   ->   | 1     |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   256
 * ...     | nm 2    |   ->   | 2     |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   257
 * ...     | nm 2    |   ->   | ..    |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   258
 * ...     | nm 2    |   ->   | 0xFE  |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   259
 * seg m+n | nm 2    |   ->   | 1     |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   260
 * ...     | nm 2    |   ->   |       |
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   261
 *
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   262
 * A value of '0' in the segmap indicates that this segment contains the beginning of
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   263
 * an nmethod. Let's walk through a simple example: If we want to find the start of
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   264
 * an nmethod that falls into seg 2, we read the value of the segmap[2]. The value
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   265
 * is an offset that points to the segment that contains the start of the nmethod.
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   266
 * Another example: If we want to get the start of nm 2, and we happen to get a pointer
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   267
 * that points to seg m+n, we first read seg[n+m], which returns '1'. So we have to
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   268
 * do one more read of the segmap[m+n-1] to finally get the segment header.
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   269
 */
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
void* CodeHeap::find_start(void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (!contains(p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  }
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   274
  size_t seg_idx = segment_for(p);
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   275
  address seg_map = (address)_segmap.low();
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   276
  if (is_segment_unused(seg_map[seg_idx])) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   279
  while (seg_map[seg_idx] > 0) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   280
    seg_idx -= (int)seg_map[seg_idx];
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   281
  }
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   282
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   283
  HeapBlock* h = block_at(seg_idx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  if (h->free()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  return h->allocated_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 35590
diff changeset
   290
CodeBlob* CodeHeap::find_blob_unsafe(void* start) const {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 35590
diff changeset
   291
  CodeBlob* result = (CodeBlob*)CodeHeap::find_start(start);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 35590
diff changeset
   292
  if (result != NULL && result->blob_contains((address)start)) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 35590
diff changeset
   293
    return result;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 35590
diff changeset
   294
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 35590
diff changeset
   295
  return NULL;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 35590
diff changeset
   296
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
size_t CodeHeap::alignment_unit() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // this will be a power of two
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  return _segment_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
size_t CodeHeap::alignment_offset() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  // The lowest address in any allocated block will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // equal to alignment_offset (mod alignment_unit).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  return sizeof(HeapBlock) & (_segment_size - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
28493
26cabf3261fa 8065894: CodeHeap::next_free should be renamed
zmajo
parents: 27420
diff changeset
   310
// Returns the current block if available and used.
26cabf3261fa 8065894: CodeHeap::next_free should be renamed
zmajo
parents: 27420
diff changeset
   311
// If not, it returns the subsequent block (if available), NULL otherwise.
26cabf3261fa 8065894: CodeHeap::next_free should be renamed
zmajo
parents: 27420
diff changeset
   312
// Free blocks are merged, therefore there is at most one free block
26cabf3261fa 8065894: CodeHeap::next_free should be renamed
zmajo
parents: 27420
diff changeset
   313
// between two used ones. As a result, the subsequent block (if available) is
26cabf3261fa 8065894: CodeHeap::next_free should be renamed
zmajo
parents: 27420
diff changeset
   314
// guaranteed to be used.
26cabf3261fa 8065894: CodeHeap::next_free should be renamed
zmajo
parents: 27420
diff changeset
   315
void* CodeHeap::next_used(HeapBlock* b) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  if (b != NULL && b->free()) b = next_block(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  assert(b == NULL || !b->free(), "must be in use or at end of heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  return (b == NULL) ? NULL : b->allocated_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
// Returns the first used HeapBlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
HeapBlock* CodeHeap::first_block() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  if (_next_segment > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    return block_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   328
HeapBlock* CodeHeap::block_start(void* q) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  HeapBlock* b = (HeapBlock*)find_start(q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  if (b == NULL) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  return b - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
// Returns the next Heap block an offset into one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
HeapBlock* CodeHeap::next_block(HeapBlock *b) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  if (b == NULL) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  size_t i = segment_for(b) + b->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  if (i < _next_segment)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    return block_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
// Returns current capacity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
size_t CodeHeap::capacity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  return _memory.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
size_t CodeHeap::max_capacity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  return _memory.reserved_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   353
int CodeHeap::allocated_segments() const {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   354
  return (int)_next_segment;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   355
}
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   356
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
size_t CodeHeap::allocated_capacity() const {
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   358
  // size of used heap - size on freelist
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   359
  return segments_to_size(_next_segment - _freelist_segments);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   362
// Returns size of the unallocated heap block
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   363
size_t CodeHeap::heap_unallocated_capacity() const {
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   364
  // Total number of segments - number currently used
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   365
  return segments_to_size(_number_of_reserved_segments - _next_segment);
7715
12998f95a334 7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents: 7397
diff changeset
   366
}
12998f95a334 7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents: 7397
diff changeset
   367
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
// Free list management
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   370
FreeBlock* CodeHeap::following_block(FreeBlock *b) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  return (FreeBlock*)(((address)b) + _segment_size * b->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
// Inserts block b after a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
void CodeHeap::insert_after(FreeBlock* a, FreeBlock* b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  assert(a != NULL && b != NULL, "must be real pointers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // Link b into the list after a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  b->set_link(a->link());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  a->set_link(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  // See if we can merge blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  merge_right(b); // Try to make b bigger
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  merge_right(a); // Try to make a include b
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
// Try to merge this block with the following block
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   388
bool CodeHeap::merge_right(FreeBlock* a) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  assert(a->free(), "must be a free block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  if (following_block(a) == a->link()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    assert(a->link() != NULL && a->link()->free(), "must be free too");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    // Update block a to include the following block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    a->set_length(a->length() + a->link()->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    a->set_link(a->link()->link());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    // Update find_start map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    size_t beg = segment_for(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    mark_segmap_as_used(beg, beg + a->length());
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   398
    _freelist_length--;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   399
    return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   401
  return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   404
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   405
void CodeHeap::add_to_freelist(HeapBlock* a) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  FreeBlock* b = (FreeBlock*)a;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   407
  _freelist_length++;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   408
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  assert(b != _freelist, "cannot be removed twice");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   411
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // Mark as free and update free space count
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   413
  _freelist_segments += b->length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  b->set_free();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  // First element in list?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  if (_freelist == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    _freelist = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    b->set_link(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   423
  // Since the freelist is ordered (smaller addresses -> larger addresses) and the
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   424
  // element we want to insert into the freelist has a smaller address than the first
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   425
  // element, we can simply add 'b' as the first element and we are done.
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   426
  if (b < _freelist) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    // Insert first in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    b->set_link(_freelist);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    _freelist = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    merge_right(_freelist);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   431
    return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   433
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   434
  // Scan for right place to put into list. List
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   435
  // is sorted by increasing addresses
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   436
  FreeBlock* prev = _freelist;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   437
  FreeBlock* cur  = _freelist->link();
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   438
  while(cur != NULL && cur < b) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   439
    assert(prev < cur, "Freelist must be ordered");
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   440
    prev = cur;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   441
    cur  = cur->link();
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   442
  }
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   443
  assert((prev < b) && (cur == NULL || b < cur), "free-list must be ordered");
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   444
  insert_after(prev, b);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   447
/**
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   448
 * Search freelist for an entry on the list with the best fit.
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   449
 * @return NULL, if no one was found
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   450
 */
27420
04e6f914cce1 8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents: 26809
diff changeset
   451
FreeBlock* CodeHeap::search_freelist(size_t length) {
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   452
  FreeBlock* found_block = NULL;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   453
  FreeBlock* found_prev  = NULL;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   454
  size_t     found_length = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   456
  FreeBlock* prev = NULL;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   457
  FreeBlock* cur = _freelist;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   458
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   459
  // Search for first block that fits
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  while(cur != NULL) {
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   461
    if (cur->length() >= length) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   462
      // Remember block, its previous element, and its length
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   463
      found_block = cur;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   464
      found_prev  = prev;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   465
      found_length = found_block->length();
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   466
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   467
      break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    // Next element in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    prev = cur;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    cur  = cur->link();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   474
  if (found_block == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    // None found
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  // Exact (or at least good enough) fit. Remove from list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  // Don't leave anything on the freelist smaller than CodeCacheMinBlockLength.
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   481
  if (found_length - length < CodeCacheMinBlockLength) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   482
    _freelist_length--;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   483
    length = found_length;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   484
    if (found_prev == NULL) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   485
      assert(_freelist == found_block, "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
      _freelist = _freelist->link();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    } else {
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   488
      assert((found_prev->link() == found_block), "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
      // Unmap element
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   490
      found_prev->set_link(found_block->link());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    // Truncate block and return a pointer to the following block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    // Set used bit and length on new block
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   495
    found_block->set_length(found_length - length);
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   496
    found_block = following_block(found_block);
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   497
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   498
    size_t beg = segment_for(found_block);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    mark_segmap_as_used(beg, beg + length);
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   500
    found_block->set_length(length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   503
  found_block->set_used();
17016
78b1c3670525 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 16670
diff changeset
   504
  _freelist_segments -= length;
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   505
  return found_block;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
//----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
void CodeHeap::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  tty->print_cr("The Heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
void CodeHeap::verify() {
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   518
  if (VerifyCodeCache) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   519
    size_t len = 0;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   520
    int count = 0;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   521
    for(FreeBlock* b = _freelist; b != NULL; b = b->link()) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   522
      len += b->length();
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   523
      count++;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   524
      // Check if we have merged all free blocks
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   525
      assert(merge_right(b) == false, "Missed merging opportunity");
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   526
    }
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   527
    // Verify that freelist contains the right amount of free space
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   528
    assert(len == _freelist_segments, "wrong freelist");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   530
    for(HeapBlock* h = first_block(); h != NULL; h = next_block(h)) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   531
      if (h->free()) count--;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   532
    }
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   533
    // Verify that the freelist contains the same number of blocks
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   534
    // than free blocks found on the full list.
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   535
    assert(count == 0, "missing free blocks");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   537
    // Verify that the number of free blocks is not out of hand.
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   538
    static int free_block_threshold = 10000;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   539
    if (count > free_block_threshold) {
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   540
      warning("CodeHeap: # of free blocks > %d", free_block_threshold);
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   541
      // Double the warning limit
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   542
      free_block_threshold *= 2;
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   543
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
}
23214
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   546
b6426873cb37 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 22551
diff changeset
   547
#endif