src/hotspot/share/gc/parallel/mutableNUMASpace.cpp
author stefank
Mon, 25 Nov 2019 12:33:15 +0100
changeset 59252 623722a6aeb9
parent 49360 886acec3b4c6
permissions -rw-r--r--
8234740: Harmonize parameter order in Atomic - cmpxchg Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 48132
diff changeset
     2
 * Copyright (c) 2006, 2018, 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: 2154
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2154
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: 2154
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: 5702
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    26
#include "gc/parallel/mutableNUMASpace.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    27
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    28
#include "gc/shared/spaceDecorator.hpp"
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 48132
diff changeset
    29
#include "memory/allocation.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    30
#include "oops/oop.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 33105
diff changeset
    31
#include "runtime/atomic.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 13195
diff changeset
    32
#include "runtime/thread.inline.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47634
diff changeset
    33
#include "runtime/threadSMR.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    34
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
46312
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    36
MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment), _must_use_large_pages(false) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12379
diff changeset
    37
  _lgrp_spaces = new (ResourceObj::C_HEAP, mtGC) GrowableArray<LGRPSpace*>(0, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _page_size = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _adaptation_cycles = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _samples_count = 0;
46312
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    41
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    42
#ifdef LINUX
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    43
  // Changing the page size can lead to freeing of memory. When using large pages
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    44
  // and the memory has been both reserved and committed, Linux does not support
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    45
  // freeing parts of it.
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    46
    if (UseLargePages && !os::can_commit_large_page_memory()) {
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    47
      _must_use_large_pages = true;
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    48
    }
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    49
#endif // LINUX
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
    50
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  update_layout(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
MutableNUMASpace::~MutableNUMASpace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    delete lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  delete lgrp_spaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    61
#ifndef PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
void MutableNUMASpace::mangle_unused_area() {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    63
  // This method should do nothing.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    64
  // It can be called on a numa space during a full compaction.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    65
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    66
void MutableNUMASpace::mangle_unused_area_complete() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    67
  // This method should do nothing.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    68
  // It can be called on a numa space during a full compaction.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    69
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    70
void MutableNUMASpace::mangle_region(MemRegion mr) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    71
  // This method should do nothing because numa spaces are not mangled.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    73
void MutableNUMASpace::set_top_for_allocations(HeapWord* v) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    74
  assert(false, "Do not mangle MutableNUMASpace's");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    75
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    76
void MutableNUMASpace::set_top_for_allocations() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    77
  // This method should do nothing.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    78
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    79
void MutableNUMASpace::check_mangled_unused_area(HeapWord* limit) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    80
  // This method should do nothing.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    81
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    82
void MutableNUMASpace::check_mangled_unused_area_complete() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    83
  // This method should do nothing.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    84
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
    85
#endif  // NOT_PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// There may be unallocated holes in the middle chunks
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
    88
// that should be filled with dead objects to ensure parsability.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void MutableNUMASpace::ensure_parsability() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    MutableSpace *s = ls->space();
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1911
diff changeset
    93
    if (s->top() < top()) { // For all spaces preceding the one containing top()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      if (s->free_in_words() > 0) {
48132
3c0ef95d12e3 8178497: Bug in MutableNUMASpace::ensure_parsability
sangheki
parents: 48105
diff changeset
    95
        HeapWord* cur_top = s->top();
12229
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
    96
        size_t words_left_to_fill = pointer_delta(s->end(), s->top());;
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
    97
        while (words_left_to_fill > 0) {
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
    98
          size_t words_to_fill = MIN2(words_left_to_fill, CollectedHeap::filler_array_max_size());
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
    99
          assert(words_to_fill >= CollectedHeap::min_fill_size(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   100
                 "Remaining size (" SIZE_FORMAT ") is too small to fill (based on " SIZE_FORMAT " and " SIZE_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   101
                 words_to_fill, words_left_to_fill, CollectedHeap::filler_array_max_size());
48132
3c0ef95d12e3 8178497: Bug in MutableNUMASpace::ensure_parsability
sangheki
parents: 48105
diff changeset
   102
          CollectedHeap::fill_with_object(cur_top, words_to_fill);
12229
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   103
          if (!os::numa_has_static_binding()) {
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   104
            size_t touched_words = words_to_fill;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
#ifndef ASSERT
12229
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   106
            if (!ZapUnusedHeapArea) {
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   107
              touched_words = MIN2((size_t)align_object_size(typeArrayOopDesc::header_size(T_INT)),
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   108
                touched_words);
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   109
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
#endif
12229
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   111
            MemRegion invalid;
48132
3c0ef95d12e3 8178497: Bug in MutableNUMASpace::ensure_parsability
sangheki
parents: 48105
diff changeset
   112
            HeapWord *crossing_start = align_up(cur_top, os::vm_page_size());
3c0ef95d12e3 8178497: Bug in MutableNUMASpace::ensure_parsability
sangheki
parents: 48105
diff changeset
   113
            HeapWord *crossing_end = align_down(cur_top + touched_words, os::vm_page_size());
12229
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   114
            if (crossing_start != crossing_end) {
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   115
              // If object header crossed a small page boundary we mark the area
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   116
              // as invalid rounding it to a page_size().
48132
3c0ef95d12e3 8178497: Bug in MutableNUMASpace::ensure_parsability
sangheki
parents: 48105
diff changeset
   117
              HeapWord *start = MAX2(align_down(cur_top, page_size()), s->bottom());
3c0ef95d12e3 8178497: Bug in MutableNUMASpace::ensure_parsability
sangheki
parents: 48105
diff changeset
   118
              HeapWord *end = MIN2(align_up(cur_top + touched_words, page_size()), s->end());
12229
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   119
              invalid = MemRegion(start, end);
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   120
            }
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   121
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   122
            ls->add_invalid_region(invalid);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   123
          }
48132
3c0ef95d12e3 8178497: Bug in MutableNUMASpace::ensure_parsability
sangheki
parents: 48105
diff changeset
   124
          cur_top += words_to_fill;
12229
c34a85c8f5aa 7103665: HeapWord*ParallelScavengeHeap::failed_mem_allocate(unsigned long,bool)+0x97
brutisso
parents: 11402
diff changeset
   125
          words_left_to_fill -= words_to_fill;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    } else {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   129
      if (!os::numa_has_static_binding()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        MemRegion invalid(s->top(), s->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        ls->add_invalid_region(invalid);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   133
#else
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   134
        if (ZapUnusedHeapArea) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   135
          MemRegion invalid(s->top(), s->end());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   136
          ls->add_invalid_region(invalid);
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   137
        } else {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   138
          return;
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   139
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#endif
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   141
      } else {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   142
          return;
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   143
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    }
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
size_t MutableNUMASpace::used_in_words() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  size_t s = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    s += lgrp_spaces()->at(i)->space()->used_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
size_t MutableNUMASpace::free_in_words() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  size_t s = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    s += lgrp_spaces()->at(i)->space()->free_in_words();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
size_t MutableNUMASpace::tlab_capacity(Thread *thr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  guarantee(thr != NULL, "No thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  int lgrp_id = thr->lgrp_id();
976
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   168
  if (lgrp_id == -1) {
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   169
    // This case can occur after the topology of the system has
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   170
    // changed. Thread can change their location, the new home
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   171
    // group will be determined during the first allocation
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   172
    // attempt. For now we can safely assume that all spaces
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   173
    // have equal size because the whole space will be reinitialized.
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   174
    if (lgrp_spaces()->length() > 0) {
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   175
      return capacity_in_bytes() / lgrp_spaces()->length();
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   176
    } else {
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   177
      assert(false, "There should be at least one locality group");
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   178
      return 0;
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   179
    }
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   180
  }
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   181
  // That's the normal case, where we know the locality group of the thread.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  return lgrp_spaces()->at(i)->space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   189
size_t MutableNUMASpace::tlab_used(Thread *thr) const {
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   190
  // Please see the comments for tlab_capacity().
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   191
  guarantee(thr != NULL, "No thread");
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   192
  int lgrp_id = thr->lgrp_id();
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   193
  if (lgrp_id == -1) {
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   194
    if (lgrp_spaces()->length() > 0) {
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   195
      return (used_in_bytes()) / lgrp_spaces()->length();
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   196
    } else {
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   197
      assert(false, "There should be at least one locality group");
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   198
      return 0;
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   199
    }
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   200
  }
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   201
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   202
  if (i == -1) {
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   203
    return 0;
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   204
  }
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   205
  return lgrp_spaces()->at(i)->space()->used_in_bytes();
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   206
}
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   207
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
   208
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
size_t MutableNUMASpace::unsafe_max_tlab_alloc(Thread *thr) const {
976
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   210
  // Please see the comments for tlab_capacity().
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  guarantee(thr != NULL, "No thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  int lgrp_id = thr->lgrp_id();
976
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   213
  if (lgrp_id == -1) {
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   214
    if (lgrp_spaces()->length() > 0) {
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   215
      return free_in_bytes() / lgrp_spaces()->length();
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   216
    } else {
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   217
      assert(false, "There should be at least one locality group");
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   218
      return 0;
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   219
    }
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   220
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  return lgrp_spaces()->at(i)->space()->free_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
1405
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   228
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   229
size_t MutableNUMASpace::capacity_in_words(Thread* thr) const {
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   230
  guarantee(thr != NULL, "No thread");
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   231
  int lgrp_id = thr->lgrp_id();
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   232
  if (lgrp_id == -1) {
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   233
    if (lgrp_spaces()->length() > 0) {
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   234
      return capacity_in_words() / lgrp_spaces()->length();
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   235
    } else {
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   236
      assert(false, "There should be at least one locality group");
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   237
      return 0;
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   238
    }
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   239
  }
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   240
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   241
  if (i == -1) {
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   242
    return 0;
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   243
  }
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   244
  return lgrp_spaces()->at(i)->space()->capacity_in_words();
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   245
}
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   246
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// Check if the NUMA topology has changed. Add and remove spaces if needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
// The update can be forced by setting the force parameter equal to true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
bool MutableNUMASpace::update_layout(bool force) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // Check if the topology had changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  bool changed = os::numa_topology_changed();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  if (force || changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    // Compute lgrp intersection. Add/remove spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    int lgrp_limit = (int)os::numa_get_groups_num();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12379
diff changeset
   255
    int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit, mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    int lgrp_num = (int)os::numa_get_leaf_groups(lgrp_ids, lgrp_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    assert(lgrp_num > 0, "There should be at least one locality group");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    // Add new spaces for the new nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    for (int i = 0; i < lgrp_num; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      for (int j = 0; j < lgrp_spaces()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        if (lgrp_spaces()->at(j)->lgrp_id() == lgrp_ids[i]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
          found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      if (!found) {
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   268
        lgrp_spaces()->append(new LGRPSpace(lgrp_ids[i], alignment()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    // Remove spaces for the removed nodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    for (int i = 0; i < lgrp_spaces()->length();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      for (int j = 0; j < lgrp_num; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        if (lgrp_spaces()->at(i)->lgrp_id() == lgrp_ids[j]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
          found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      if (!found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        delete lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        lgrp_spaces()->remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25351
diff changeset
   289
    FREE_C_HEAP_ARRAY(int, lgrp_ids);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    if (changed) {
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47634
diff changeset
   292
      for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
        thread->set_lgrp_id(-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
// Bias region towards the first-touching lgrp. Set the right page sizes.
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   302
void MutableNUMASpace::bias_region(MemRegion mr, int lgrp_id) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   303
  HeapWord *start = align_up(mr.start(), page_size());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   304
  HeapWord *end = align_down(mr.end(), page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  if (end > start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    MemRegion aligned_region(start, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    assert((intptr_t)aligned_region.start()     % page_size() == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
           (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    assert(region().contains(aligned_region), "Sanity");
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   310
    // First we tell the OS which page size we want in the given range. The underlying
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   311
    // large page can be broken down if we require small pages.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    os::realign_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size());
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   313
    // Then we uncommit the pages in the range.
11402
739e52129c84 7124829: NUMA: memory leak on Linux with large pages
iveresov
parents: 10565
diff changeset
   314
    os::free_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size());
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   315
    // And make them local/first-touch biased.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   316
    os::numa_make_local((char*)aligned_region.start(), aligned_region.byte_size(), lgrp_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
// Free all pages in the region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
void MutableNUMASpace::free_region(MemRegion mr) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   322
  HeapWord *start = align_up(mr.start(), page_size());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   323
  HeapWord *end = align_down(mr.end(), page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  if (end > start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    MemRegion aligned_region(start, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    assert((intptr_t)aligned_region.start()     % page_size() == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
           (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    assert(region().contains(aligned_region), "Sanity");
11402
739e52129c84 7124829: NUMA: memory leak on Linux with large pages
iveresov
parents: 10565
diff changeset
   329
    os::free_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
// Update space layout. Perform adaptation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
void MutableNUMASpace::update() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  if (update_layout(false)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    // If the topology has changed, make all chunks zero-sized.
976
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   337
    // And clear the alloc-rate statistics.
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   338
    // In future we may want to handle this more gracefully in order
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   339
    // to avoid the reallocation of the pages as much as possible.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
976
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   341
      LGRPSpace *ls = lgrp_spaces()->at(i);
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   342
      MutableSpace *s = ls->space();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      s->set_end(s->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      s->set_top(s->bottom());
976
241230d48896 6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents: 971
diff changeset
   345
      ls->clear_alloc_rate();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    }
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   347
    // A NUMA space is never mangled
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   348
    initialize(region(),
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   349
               SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   350
               SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    bool should_initialize = false;
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   353
    if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   354
      for (int i = 0; i < lgrp_spaces()->length(); i++) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   355
        if (!lgrp_spaces()->at(i)->invalid_region().is_empty()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   356
          should_initialize = true;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   357
          break;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   358
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    if (should_initialize ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
        (UseAdaptiveNUMAChunkSizing && adaptation_cycles() < samples_count())) {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   364
      // A NUMA space is never mangled
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   365
      initialize(region(),
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   366
                 SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   367
                 SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  if (NUMAStats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      lgrp_spaces()->at(i)->accumulate_statistics(page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  scan_pages(NUMAPageScanRate);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
// Scan pages. Free pages that have smaller size or wrong placement.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
void MutableNUMASpace::scan_pages(size_t page_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  size_t pages_per_chunk = page_count / lgrp_spaces()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  if (pages_per_chunk > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      ls->scan_pages(page_size(), pages_per_chunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// Accumulate statistics about the allocation rate of each lgrp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
void MutableNUMASpace::accumulate_statistics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  if (UseAdaptiveNUMAChunkSizing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
      lgrp_spaces()->at(i)->sample();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    increment_samples_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  if (NUMAStats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      lgrp_spaces()->at(i)->accumulate_statistics(page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
// Get the current size of a chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
// This function computes the size of the chunk based on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
// difference between chunk ends. This allows it to work correctly in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
// case the whole space is resized and during the process of adaptive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
// chunk resizing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
size_t MutableNUMASpace::current_chunk_size(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  HeapWord *cur_end, *prev_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  if (i == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    prev_end = bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    prev_end = lgrp_spaces()->at(i - 1)->space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  if (i == lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    cur_end = end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    cur_end = lgrp_spaces()->at(i)->space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  if (cur_end > prev_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    return pointer_delta(cur_end, prev_end, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
// Return the default chunk size by equally diving the space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
// page_size() aligned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
size_t MutableNUMASpace::default_chunk_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  return base_space_size() / lgrp_spaces()->length() * page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
// Produce a new chunk size. page_size() aligned.
1423
1233b1e85dfd 6753547: NUMA allocator: Invalid chunk size computation during adaptive resizing
iveresov
parents: 1405
diff changeset
   438
// This function is expected to be called on sequence of i's from 0 to
1233b1e85dfd 6753547: NUMA allocator: Invalid chunk size computation during adaptive resizing
iveresov
parents: 1405
diff changeset
   439
// lgrp_spaces()->length().
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
size_t MutableNUMASpace::adaptive_chunk_size(int i, size_t limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  size_t pages_available = base_space_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  for (int j = 0; j < i; j++) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   443
    pages_available -= align_down(current_chunk_size(j), page_size()) / page_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  pages_available -= lgrp_spaces()->length() - i - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  assert(pages_available > 0, "No pages left");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  float alloc_rate = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  for (int j = i; j < lgrp_spaces()->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    alloc_rate += lgrp_spaces()->at(j)->alloc_rate()->average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  size_t chunk_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  if (alloc_rate > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    LGRPSpace *ls = lgrp_spaces()->at(i);
1423
1233b1e85dfd 6753547: NUMA allocator: Invalid chunk size computation during adaptive resizing
iveresov
parents: 1405
diff changeset
   454
    chunk_size = (size_t)(ls->alloc_rate()->average() / alloc_rate * pages_available) * page_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  chunk_size = MAX2(chunk_size, page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  if (limit > 0) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   459
    limit = align_down(limit, page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    if (chunk_size > current_chunk_size(i)) {
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   461
      size_t upper_bound = pages_available * page_size();
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   462
      if (upper_bound > limit &&
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   463
          current_chunk_size(i) < upper_bound - limit) {
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   464
        // The resulting upper bound should not exceed the available
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   465
        // amount of memory (pages_available * page_size()).
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   466
        upper_bound = current_chunk_size(i) + limit;
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   467
      }
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   468
      chunk_size = MIN2(chunk_size, upper_bound);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    } else {
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   470
      size_t lower_bound = page_size();
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   471
      if (current_chunk_size(i) > limit) { // lower_bound shouldn't underflow.
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   472
        lower_bound = current_chunk_size(i) - limit;
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   473
      }
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 1423
diff changeset
   474
      chunk_size = MAX2(chunk_size, lower_bound);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  assert(chunk_size <= pages_available * page_size(), "Chunk size out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  return chunk_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
// Return the bottom_region and the top_region. Align them to page_size() boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
// |------------------new_region---------------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
// |----bottom_region--|---intersection---|------top_region------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
void MutableNUMASpace::select_tails(MemRegion new_region, MemRegion intersection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
                                    MemRegion* bottom_region, MemRegion *top_region) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  // Is there bottom?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  if (new_region.start() < intersection.start()) { // Yes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    // Try to coalesce small pages into a large one.
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   490
    if (UseLargePages && page_size() >= alignment()) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   491
      HeapWord* p = align_up(intersection.start(), alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
      if (new_region.contains(p)
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   493
          && pointer_delta(p, new_region.start(), sizeof(char)) >= alignment()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
        if (intersection.contains(p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
          intersection = MemRegion(p, intersection.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
          intersection = MemRegion(p, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    *bottom_region = MemRegion(new_region.start(), intersection.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    *bottom_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  // Is there top?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  if (intersection.end() < new_region.end()) { // Yes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    // Try to coalesce small pages into a large one.
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   509
    if (UseLargePages && page_size() >= alignment()) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   510
      HeapWord* p = align_down(intersection.end(), alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      if (new_region.contains(p)
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   512
          && pointer_delta(new_region.end(), p, sizeof(char)) >= alignment()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
        if (intersection.contains(p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
          intersection = MemRegion(intersection.start(), p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
          intersection = MemRegion(p, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    *top_region = MemRegion(intersection.end(), new_region.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    *top_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
// Try to merge the invalid region with the bottom or top region by decreasing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
// the intersection area. Return the invalid_region aligned to the page_size()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
// boundary if it's inside the intersection. Return non-empty invalid_region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
// if it lies inside the intersection (also page-aligned).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
// |------------------new_region---------------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
// |----------------|-------invalid---|--------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
// |----bottom_region--|---intersection---|------top_region------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
void MutableNUMASpace::merge_regions(MemRegion new_region, MemRegion* intersection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
                                     MemRegion *invalid_region) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  if (intersection->start() >= invalid_region->start() && intersection->contains(invalid_region->end())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    *intersection = MemRegion(invalid_region->end(), intersection->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    *invalid_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    if (intersection->end() <= invalid_region->end() && intersection->contains(invalid_region->start())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      *intersection = MemRegion(intersection->start(), invalid_region->start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      *invalid_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
      if (intersection->equals(*invalid_region) || invalid_region->contains(*intersection)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        *intersection = MemRegion(new_region.start(), new_region.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
        *invalid_region = MemRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
      } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
        if (intersection->contains(invalid_region)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
            // That's the only case we have to make an additional bias_region() call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
            HeapWord* start = invalid_region->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
            HeapWord* end = invalid_region->end();
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   551
            if (UseLargePages && page_size() >= alignment()) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   552
              HeapWord *p = align_down(start, alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
              if (new_region.contains(p)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
                start = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
              }
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   556
              p = align_up(end, alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
              if (new_region.contains(end)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
                end = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
            if (intersection->start() > start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
              *intersection = MemRegion(start, intersection->end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
            if (intersection->end() < end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
              *intersection = MemRegion(intersection->start(), end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
            *invalid_region = MemRegion(start, end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   571
void MutableNUMASpace::initialize(MemRegion mr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   572
                                  bool clear_space,
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   573
                                  bool mangle_space,
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   574
                                  bool setup_pages) {
22775
52bc5222f5f1 8026849: Fix typos in the GC code, part 2
jwilhelm
parents: 22552
diff changeset
   575
  assert(clear_space, "Reallocation will destroy data!");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  assert(lgrp_spaces()->length() > 0, "There should be at least one space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  MemRegion old_region = region(), new_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  set_bottom(mr.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  set_end(mr.end());
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   581
  // Must always clear the space
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   582
  clear(SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  // Compute chunk sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  size_t prev_page_size = page_size();
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   586
  set_page_size(UseLargePages ? alignment() : os::vm_page_size());
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   587
  HeapWord* rounded_bottom = align_up(bottom(), page_size());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   588
  HeapWord* rounded_end = align_down(end(), page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  size_t base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  // Try small pages if the chunk size is too small
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  if (base_space_size_pages / lgrp_spaces()->length() == 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
      && page_size() > (size_t)os::vm_page_size()) {
46312
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
   594
    // Changing the page size below can lead to freeing of memory. So we fail initialization.
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
   595
    if (_must_use_large_pages) {
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
   596
      vm_exit_during_initialization("Failed initializing NUMA with large pages. Too small heap size");
385a8b027e7d 8023905: Failing to initialize VM with small initial heap when NUMA and large pages are enabled
sangheki
parents: 40655
diff changeset
   597
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    set_page_size(os::vm_page_size());
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   599
    rounded_bottom = align_up(bottom(), page_size());
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   600
    rounded_end = align_down(end(), page_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  guarantee(base_space_size_pages / lgrp_spaces()->length() > 0, "Space too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  set_base_space_size(base_space_size_pages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  // Handle space resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  MemRegion top_region, bottom_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  if (!old_region.equals(region())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    new_region = MemRegion(rounded_bottom, rounded_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    MemRegion intersection = new_region.intersection(old_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    if (intersection.start() == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
        intersection.end() == NULL   ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
        prev_page_size > page_size()) { // If the page size got smaller we have to change
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
                                        // the page size preference for the whole space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
      intersection = MemRegion(new_region.start(), new_region.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    select_tails(new_region, intersection, &bottom_region, &top_region);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   618
    bias_region(bottom_region, lgrp_spaces()->at(0)->lgrp_id());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   619
    bias_region(top_region, lgrp_spaces()->at(lgrp_spaces()->length() - 1)->lgrp_id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  // Check if the space layout has changed significantly?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  // This happens when the space has been resized so that either head or tail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  // chunk became less than a page.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  bool layout_valid = UseAdaptiveNUMAChunkSizing          &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
                      current_chunk_size(0) > page_size() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
                      current_chunk_size(lgrp_spaces()->length() - 1) > page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    MutableSpace *s = ls->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    old_region = s->region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    size_t chunk_byte_size = 0, old_chunk_byte_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    if (i < lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
      if (!UseAdaptiveNUMAChunkSizing                                ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
          (UseAdaptiveNUMAChunkSizing && NUMAChunkResizeWeight == 0) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
           samples_count() < AdaptiveSizePolicyReadyThreshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
        // No adaptation. Divide the space equally.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
        chunk_byte_size = default_chunk_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
      } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
        if (!layout_valid || NUMASpaceResizeRate == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
          // Fast adaptation. If no space resize rate is set, resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
          // the chunks instantly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
          chunk_byte_size = adaptive_chunk_size(i, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
          // Slow adaptation. Resize the chunks moving no more than
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
          // NUMASpaceResizeRate bytes per collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
          size_t limit = NUMASpaceResizeRate /
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
                         (lgrp_spaces()->length() * (lgrp_spaces()->length() + 1) / 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
          chunk_byte_size = adaptive_chunk_size(i, MAX2(limit * (i + 1), page_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      assert(chunk_byte_size >= page_size(), "Chunk size too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
      assert(chunk_byte_size <= capacity_in_bytes(), "Sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    if (i == 0) { // Bottom chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      if (i != lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
        new_region = MemRegion(bottom(), rounded_bottom + (chunk_byte_size >> LogHeapWordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
        new_region = MemRegion(bottom(), end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
      if (i < lgrp_spaces()->length() - 1) { // Middle chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
        MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
        new_region = MemRegion(ps->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
                               ps->end() + (chunk_byte_size >> LogHeapWordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
      } else { // Top chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
        MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
        new_region = MemRegion(ps->end(), end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    guarantee(region().contains(new_region), "Region invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    // The general case:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    // |---------------------|--invalid---|--------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    // |------------------new_region---------------------------------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    // |----bottom_region--|---intersection---|------top_region------|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    //                     |----old_region----|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    // The intersection part has all pages in place we don't need to migrate them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    // Pages for the top and bottom part should be freed and then reallocated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    MemRegion intersection = old_region.intersection(new_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
    if (intersection.start() == NULL || intersection.end() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
      intersection = MemRegion(new_region.start(), new_region.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   691
    if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   692
      MemRegion invalid_region = ls->invalid_region().intersection(new_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   693
      // Invalid region is a range of memory that could've possibly
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   694
      // been allocated on the other node. That's relevant only on Solaris where
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   695
      // there is no static memory binding.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   696
      if (!invalid_region.is_empty()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   697
        merge_regions(new_region, &intersection, &invalid_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   698
        free_region(invalid_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   699
        ls->set_invalid_region(MemRegion());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   700
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
    }
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   702
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    select_tails(new_region, intersection, &bottom_region, &top_region);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   704
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   705
    if (!os::numa_has_static_binding()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   706
      // If that's a system with the first-touch policy then it's enough
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   707
      // to free the pages.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   708
      free_region(bottom_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   709
      free_region(top_region);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   710
    } else {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   711
      // In a system with static binding we have to change the bias whenever
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   712
      // we reshape the heap.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   713
      bias_region(bottom_region, ls->lgrp_id());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   714
      bias_region(top_region, ls->lgrp_id());
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   715
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   717
    // Clear space (set top = bottom) but never mangle.
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1668
diff changeset
   718
    s->initialize(new_region, SpaceDecorator::Clear, SpaceDecorator::DontMangle, MutableSpace::DontSetupPages);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    set_adaptation_cycles(samples_count());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
// Set the top of the whole space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
// Mark the the holes in chunks below the top() as invalid.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
void MutableNUMASpace::set_top(HeapWord* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  bool found_top = false;
616
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   728
  for (int i = 0; i < lgrp_spaces()->length();) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    MutableSpace *s = ls->space();
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   731
    HeapWord *top = MAX2(align_down(s->top(), page_size()), s->bottom());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
    if (s->contains(value)) {
616
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   734
      // Check if setting the chunk's top to a given value would create a hole less than
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   735
      // a minimal object; assuming that's not the last chunk in which case we don't care.
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   736
      if (i < lgrp_spaces()->length() - 1) {
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   737
        size_t remainder = pointer_delta(s->end(), value);
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1615
diff changeset
   738
        const size_t min_fill_size = CollectedHeap::min_fill_size();
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1615
diff changeset
   739
        if (remainder < min_fill_size && remainder > 0) {
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1615
diff changeset
   740
          // Add a minimum size filler object; it will cross the chunk boundary.
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1615
diff changeset
   741
          CollectedHeap::fill_with_object(value, min_fill_size);
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1615
diff changeset
   742
          value += min_fill_size;
616
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   743
          assert(!s->contains(value), "Should be in the next chunk");
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   744
          // Restart the loop from the same chunk, since the value has moved
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   745
          // to the next one.
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   746
          continue;
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   747
        }
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   748
      }
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   749
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   750
      if (!os::numa_has_static_binding() && top < value && top < s->end()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
        ls->add_invalid_region(MemRegion(top, value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
      s->set_top(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      found_top = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
        if (found_top) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
            s->set_top(s->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
        } else {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   759
          if (!os::numa_has_static_binding() && top < s->end()) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   760
            ls->add_invalid_region(MemRegion(top, s->end()));
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   761
          }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   762
          s->set_top(s->end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    }
616
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   765
    i++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  MutableSpace::set_top(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   770
void MutableNUMASpace::clear(bool mangle_space) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  MutableSpace::set_top(bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   773
    // Never mangle NUMA spaces because the mangling will
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   774
    // bind the memory to a possibly unwanted lgroup.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 616
diff changeset
   775
    lgrp_spaces()->at(i)->space()->clear(SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   779
/*
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   780
   Linux supports static memory binding, therefore the most part of the
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   781
   logic dealing with the possible invalid page allocation is effectively
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   782
   disabled. Besides there is no notion of the home node in Linux. A
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   783
   thread is allowed to migrate freely. Although the scheduler is rather
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   784
   reluctant to move threads between the nodes. We check for the current
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   785
   node every allocation. And with a high probability a thread stays on
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   786
   the same node for some time allowing local access to recently allocated
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   787
   objects.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   788
 */
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   789
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
HeapWord* MutableNUMASpace::allocate(size_t size) {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   791
  Thread* thr = Thread::current();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   792
  int lgrp_id = thr->lgrp_id();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   793
  if (lgrp_id == -1 || !os::numa_has_group_homing()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    lgrp_id = os::numa_get_group_id();
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   795
    thr->set_lgrp_id(lgrp_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  // It is possible that a new CPU has been hotplugged and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  // we haven't reshaped the space accordingly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    i = os::random() % lgrp_spaces()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
1405
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   806
  LGRPSpace* ls = lgrp_spaces()->at(i);
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   807
  MutableSpace *s = ls->space();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  HeapWord *p = s->allocate(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   810
  if (p != NULL) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   811
    size_t remainder = s->free_in_words();
5694
1e0532a6abff 6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents: 2154
diff changeset
   812
    if (remainder < CollectedHeap::min_fill_size() && remainder > 0) {
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   813
      s->set_top(s->top() - size);
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   814
      p = NULL;
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   815
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  if (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    if (top() < s->top()) { // Keep _top updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      MutableSpace::set_top(s->top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  }
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   822
  // Make the page allocation happen here if there is no static binding..
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   823
  if (p != NULL && !os::numa_has_static_binding()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
      *(int*)i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  }
1405
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   828
  if (p == NULL) {
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   829
    ls->set_allocation_failed();
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   830
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
// This version is lock-free.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
HeapWord* MutableNUMASpace::cas_allocate(size_t size) {
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   836
  Thread* thr = Thread::current();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   837
  int lgrp_id = thr->lgrp_id();
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   838
  if (lgrp_id == -1 || !os::numa_has_group_homing()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    lgrp_id = os::numa_get_group_id();
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   840
    thr->set_lgrp_id(lgrp_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  // It is possible that a new CPU has been hotplugged and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  // we haven't reshaped the space accordingly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  if (i == -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    i = os::random() % lgrp_spaces()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  }
1405
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   849
  LGRPSpace *ls = lgrp_spaces()->at(i);
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   850
  MutableSpace *s = ls->space();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  HeapWord *p = s->cas_allocate(size);
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   852
  if (p != NULL) {
616
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   853
    size_t remainder = pointer_delta(s->end(), p + size);
5694
1e0532a6abff 6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents: 2154
diff changeset
   854
    if (remainder < CollectedHeap::min_fill_size() && remainder > 0) {
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   855
      if (s->cas_deallocate(p, size)) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   856
        // We were the last to allocate and created a fragment less than
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   857
        // a minimal object.
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   858
        p = NULL;
616
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   859
      } else {
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   860
        guarantee(false, "Deallocation should always succeed");
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   861
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  if (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    HeapWord* cur_top, *cur_chunk_top = p + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
    while ((cur_top = top()) < cur_chunk_top) { // Keep _top updated.
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 49360
diff changeset
   867
      if (Atomic::cmpxchg(top_addr(), cur_top, cur_chunk_top) == cur_top) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   873
  // Make the page allocation happen here if there is no static binding.
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   874
  if (p != NULL && !os::numa_has_static_binding() ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
    for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
      *(int*)i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  }
1405
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   879
  if (p == NULL) {
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   880
    ls->set_allocation_failed();
ce6e6fe90107 6740923: NUMA allocator: Ensure the progress of adaptive chunk resizing
iveresov
parents: 977
diff changeset
   881
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
void MutableNUMASpace::print_short_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  MutableSpace::print_short_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  st->print(" (");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
    st->print("lgrp %d: ", lgrp_spaces()->at(i)->lgrp_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    lgrp_spaces()->at(i)->space()->print_short_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
    if (i < lgrp_spaces()->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
      st->print(", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  st->print(")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
void MutableNUMASpace::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  MutableSpace::print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  for (int i = 0; i < lgrp_spaces()->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    LGRPSpace *ls = lgrp_spaces()->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    st->print("    lgrp %d", ls->lgrp_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
    ls->space()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    if (NUMAStats) {
391
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   905
      for (int i = 0; i < lgrp_spaces()->length(); i++) {
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   906
        lgrp_spaces()->at(i)->accumulate_statistics(page_size());
f889070a8684 6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents: 388
diff changeset
   907
      }
24092
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22775
diff changeset
   908
      st->print("    local/remote/unbiased/uncommitted: " SIZE_FORMAT "K/"
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22775
diff changeset
   909
                SIZE_FORMAT "K/" SIZE_FORMAT "K/" SIZE_FORMAT
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22775
diff changeset
   910
                "K, large/small pages: " SIZE_FORMAT "/" SIZE_FORMAT "\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
                ls->space_stats()->_local_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
                ls->space_stats()->_remote_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
                ls->space_stats()->_unbiased_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
                ls->space_stats()->_uncommited_space / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
                ls->space_stats()->_large_pages,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
                ls->space_stats()->_small_pages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
12379
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 12229
diff changeset
   921
void MutableNUMASpace::verify() {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   922
  // This can be called after setting an arbitrary value to the space's top,
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   923
  // so an object can cross the chunk boundary. We ensure the parsability
616
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   924
  // of the space and just walk the objects in linear fashion.
4f2dfc0168e2 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 391
diff changeset
   925
  ensure_parsability();
12379
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 12229
diff changeset
   926
  MutableSpace::verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
// Scan pages and gather stats about page placement and size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
void MutableNUMASpace::LGRPSpace::accumulate_statistics(size_t page_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  clear_space_stats();
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   932
  char *start = (char*)align_up(space()->bottom(), page_size);
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   933
  char* end = (char*)align_down(space()->end(), page_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  if (start < end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    for (char *p = start; p < end;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
      os::page_info info;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
      if (os::get_page_info(p, &info)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
        if (info.size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
          if (info.size > (size_t)os::vm_page_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
            space_stats()->_large_pages++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
            space_stats()->_small_pages++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
          if (info.lgrp_id == lgrp_id()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
            space_stats()->_local_space += info.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
            space_stats()->_remote_space += info.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
          p += info.size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
          p += os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
          space_stats()->_uncommited_space += os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  space_stats()->_unbiased_space = pointer_delta(start, space()->bottom(), sizeof(char)) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
                                   pointer_delta(space()->end(), end, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
// Scan page_count pages and verify if they have the right size and right placement.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
// If invalid pages are found they are freed in hope that subsequent reallocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
// will be more successful.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
void MutableNUMASpace::LGRPSpace::scan_pages(size_t page_size, size_t page_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
{
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   969
  char* range_start = (char*)align_up(space()->bottom(), page_size);
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 46312
diff changeset
   970
  char* range_end = (char*)align_down(space()->end(), page_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  if (range_start > last_page_scanned() || last_page_scanned() >= range_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    set_last_page_scanned(range_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  char *scan_start = last_page_scanned();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  char* scan_end = MIN2(scan_start + page_size * page_count, range_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
  os::page_info page_expected, page_found;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  page_expected.size = page_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  page_expected.lgrp_id = lgrp_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  char *s = scan_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  while (s < scan_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    char *e = os::scan_pages(s, (char*)scan_end, &page_expected, &page_found);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    if (e == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    if (e != scan_end) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   990
      assert(e < scan_end, "e: " PTR_FORMAT " scan_end: " PTR_FORMAT, p2i(e), p2i(scan_end));
15955
6d0d8bea2bcc 8004697: SIGSEGV on Solaris sparc with -XX:+UseNUMA
stefank
parents: 14583
diff changeset
   991
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
      if ((page_expected.size != page_size || page_expected.lgrp_id != lgrp_id())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
          && page_expected.size != 0) {
11402
739e52129c84 7124829: NUMA: memory leak on Linux with large pages
iveresov
parents: 10565
diff changeset
   994
        os::free_memory(s, pointer_delta(e, s, sizeof(char)), page_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
      page_expected = page_found;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
    s = e;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  set_last_page_scanned(scan_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
}