hotspot/src/share/vm/gc_implementation/parallelScavenge/objectStartArray.hpp
author sangheki
Mon, 16 Feb 2015 08:38:23 -0800
changeset 29082 cff77cc6a869
parent 24098 48f07e2c74de
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
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13195
diff changeset
     2
 * Copyright (c) 2001, 2012, 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: 2131
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
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: 2131
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
#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "gc_implementation/parallelScavenge/psVirtualspace.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/memRegion.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// This class can be used to locate the beginning of an object in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// covered region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    38
class ObjectStartArray : public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
 friend class VerifyObjectStartArrayClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  PSVirtualSpace  _virtual_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  MemRegion       _reserved_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  MemRegion       _covered_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  MemRegion       _blocks_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  jbyte*          _raw_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  jbyte*          _offset_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  enum BlockValueConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    clean_block                  = -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  enum BlockSizeConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    block_shift                  = 9,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    block_size                   = 1 << block_shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    block_size_in_words          = block_size / sizeof(HeapWord)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Mapping from address to object start array entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  jbyte* block_for_addr(void* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    assert(_covered_region.contains(p),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
           "out of bounds access to object start array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    jbyte* result = &_offset_base[uintptr_t(p) >> block_shift];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    assert(_blocks_region.contains(result),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
           "out of bounds result in byte_for");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Mapping from object start array entry to address of first word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  HeapWord* addr_for_block(jbyte* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    assert(_blocks_region.contains(p),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
           "out of bounds access to object start array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    size_t delta = pointer_delta(p, _offset_base, sizeof(jbyte));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    HeapWord* result = (HeapWord*) (delta << block_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    assert(_covered_region.contains(result),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
           "out of bounds accessor from card marking array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // Mapping that includes the derived offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // If the block is clean, returns the last address in the covered region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // If the block is < index 0, returns the start of the covered region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  HeapWord* offset_addr_for_block (jbyte* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    // We have to do this before the assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if (p < _raw_base) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      return _covered_region.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    assert(_blocks_region.contains(p),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
           "out of bounds access to object start array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    if (*p == clean_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      return _covered_region.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    size_t delta = pointer_delta(p, _offset_base, sizeof(jbyte));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    HeapWord* result = (HeapWord*) (delta << block_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    result += *p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    assert(_covered_region.contains(result),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
           "out of bounds accessor from card marking array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // This method is in lieu of a constructor, so that this class can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // embedded inline in other classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  void initialize(MemRegion reserved_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  void set_covered_region(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  MemRegion covered_region() { return _covered_region; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
29082
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   122
#define assert_covered_region_contains(addr)                                                                 \
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   123
        assert(_covered_region.contains(addr),                                                               \
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   124
               err_msg(#addr " (" PTR_FORMAT ") is not in covered region [" PTR_FORMAT ", " PTR_FORMAT "]",  \
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   125
                       p2i(addr), p2i(_covered_region.start()), p2i(_covered_region.end())))
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   126
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  void allocate_block(HeapWord* p) {
29082
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   128
    assert_covered_region_contains(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    jbyte* block = block_for_addr(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    HeapWord* block_base = addr_for_block(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    size_t offset = pointer_delta(p, block_base, sizeof(HeapWord*));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    assert(offset < 128, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    // When doing MT offsets, we can't assert this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    //assert(offset > *block, "Found backwards allocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    *block = (jbyte)offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // Optimized for finding the first object that crosses into
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // a given block. The blocks contain the offset of the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // object in that block. Scroll backwards by one, and the first
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
   141
  // object hit should be at the beginning of the block
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  HeapWord* object_start(HeapWord* addr) const {
29082
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   143
    assert_covered_region_contains(addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    jbyte* block = block_for_addr(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    HeapWord* scroll_forward = offset_addr_for_block(block--);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    while (scroll_forward > addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      scroll_forward = offset_addr_for_block(block--);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    HeapWord* next = scroll_forward;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    while (next <= addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      scroll_forward = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      next += oop(next)->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    assert(scroll_forward <= addr, "wrong order for current and arg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    assert(addr <= next, "wrong order for arg and next");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    return scroll_forward;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  bool is_block_allocated(HeapWord* addr) {
29082
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   161
    assert_covered_region_contains(addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    jbyte* block = block_for_addr(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if (*block == clean_block)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
29082
cff77cc6a869 8073115: assert(_covered_region.contains(p)) needs better error messages
sangheki
parents: 24098
diff changeset
   168
#undef assert_covered_region_contains
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // Return true if an object starts in the range of heap addresses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // If an object starts at an address corresponding to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // "start", the method will return true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  bool object_starts_in_range(HeapWord* start_addr, HeapWord* end_addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   175
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   176
#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP