hotspot/src/share/vm/gc_implementation/parallelScavenge/objectStartArray.cpp
author sangheki
Mon, 16 Feb 2015 08:38:23 -0800
changeset 29082 cff77cc6a869
parent 22549 d1ef75b0a43a
permissions -rw-r--r--
8073115: assert(_covered_region.contains(p)) needs better error messages Summary: Changed to print out related values Reviewed-by: jwilhelm, brutisso, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 17087
diff changeset
     2
 * Copyright (c) 2001, 2013, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "gc_implementation/parallelScavenge/objectStartArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/cardTableModRefBS.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/java.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    31
#include "services/memTracker.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
void ObjectStartArray::initialize(MemRegion reserved_region) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // We're based on the assumption that we use the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // size blocks as the card table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  assert((int)block_size == (int)CardTableModRefBS::card_size, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  assert((int)block_size <= 512, "block_size must be less than or equal to 512");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // Calculate how much space must be reserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _reserved_region = reserved_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  size_t bytes_to_reserve = reserved_region.word_size() / block_size_in_words;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  assert(bytes_to_reserve > 0, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  bytes_to_reserve =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    align_size_up(bytes_to_reserve, os::vm_allocation_granularity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Do not use large-pages for the backing store. The one large page region
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // will be used for the heap proper.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  ReservedSpace backing_store(bytes_to_reserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  if (!backing_store.is_reserved()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    vm_exit_during_initialization("Could not reserve space for ObjectStartArray");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    54
  MemTracker::record_virtual_memory_type((address)backing_store.base(), mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // We do not commit any memory initially
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if (!_virtual_space.initialize(backing_store, 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    vm_exit_during_initialization("Could not commit space for ObjectStartArray");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _raw_base = (jbyte*)_virtual_space.low_boundary();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    62
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  if (_raw_base == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    vm_exit_during_initialization("Could not get raw_base address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    67
  MemTracker::record_virtual_memory_type((address)_raw_base, mtGC);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    68
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    69
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _offset_base = _raw_base - (size_t(reserved_region.start()) >> block_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _covered_region.set_start(reserved_region.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  _covered_region.set_word_size(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  _blocks_region.set_start((HeapWord*)_raw_base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  _blocks_region.set_word_size(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
void ObjectStartArray::set_covered_region(MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  assert(_reserved_region.contains(mr), "MemRegion outside of reserved space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  assert(_reserved_region.start() == mr.start(), "Attempt to move covered region");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  HeapWord* low_bound  = mr.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  HeapWord* high_bound = mr.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  assert((uintptr_t(low_bound)  & (block_size - 1))  == 0, "heap must start at block boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  assert((uintptr_t(high_bound) & (block_size - 1))  == 0, "heap must end at block boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  size_t requested_blocks_size_in_bytes = mr.word_size() / block_size_in_words;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Only commit memory in page sized chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  requested_blocks_size_in_bytes =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    align_size_up(requested_blocks_size_in_bytes, os::vm_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  _covered_region = mr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  size_t current_blocks_size_in_bytes = _blocks_region.byte_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  if (requested_blocks_size_in_bytes > current_blocks_size_in_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // Expand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    size_t expand_by = requested_blocks_size_in_bytes - current_blocks_size_in_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    if (!_virtual_space.expand_by(expand_by)) {
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 13728
diff changeset
   102
      vm_exit_out_of_memory(expand_by, OOM_MMAP_ERROR, "object start array expansion");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // Clear *only* the newly allocated region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    memset(_blocks_region.end(), clean_block, expand_by);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (requested_blocks_size_in_bytes < current_blocks_size_in_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    // Shrink
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    size_t shrink_by = current_blocks_size_in_bytes - requested_blocks_size_in_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    _virtual_space.shrink_by(shrink_by);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  _blocks_region.set_word_size(requested_blocks_size_in_bytes / sizeof(HeapWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  assert(requested_blocks_size_in_bytes % sizeof(HeapWord) == 0, "Block table not expanded in word sized increment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  assert(requested_blocks_size_in_bytes == _blocks_region.byte_size(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  assert(block_for_addr(low_bound) == &_raw_base[0], "Checking start of map");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  assert(block_for_addr(high_bound-1) <= &_raw_base[_blocks_region.byte_size()-1], "Checking end of map");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
void ObjectStartArray::reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  memset(_blocks_region.start(), clean_block, _blocks_region.byte_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
bool ObjectStartArray::object_starts_in_range(HeapWord* start_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                                              HeapWord* end_addr) const {
29082
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 22549
diff changeset
   129
  assert(start_addr <= end_addr,
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 22549
diff changeset
   130
         err_msg("Range is wrong. start_addr (" PTR_FORMAT ") is after end_addr (" PTR_FORMAT ")",
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 22549
diff changeset
   131
                 p2i(start_addr), p2i(end_addr)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  if (start_addr > end_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  jbyte* start_block = block_for_addr(start_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  jbyte* end_block = block_for_addr(end_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  for (jbyte* block = start_block; block <= end_block; block++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    if (*block != clean_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
22549
d1ef75b0a43a 8020277: Young GC could be extremely slow due to assertion in ObjectStartArray::object_starts_in_range
sjohanss
parents: 22234
diff changeset
   144
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
}