hotspot/src/share/vm/gc/shared/memset_with_concurrent_readers.cpp
author brutisso
Fri, 11 Mar 2016 11:34:22 +0100
changeset 37073 c39d0903390b
parent 36073 1c0381cc1e1d
permissions -rw-r--r--
8151605: Change warning() to log_warning(gc) in the GC code Reviewed-by: jwilhelm, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     1
/*
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     4
 *
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     7
 * published by the Free Software Foundation.
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     8
 *
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    13
 * accompanied this code).
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    14
 *
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    18
 *
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    21
 * questions.
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    22
 *
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    23
 */
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    24
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    25
#include "precompiled.hpp"
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    26
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    27
#include <string.h>
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    28
#include "gc/shared/memset_with_concurrent_readers.hpp"
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    29
#include "utilities/debug.hpp"
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    31
#include "utilities/macros.hpp"
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    32
#include "utilities/ostream.hpp"
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    33
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    34
#if INCLUDE_ALL_GCS
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    35
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    36
// Unit test
36073
1c0381cc1e1d 8149141: Optimized build is broken
vlivanov
parents: 32598
diff changeset
    37
#ifndef PRODUCT
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    38
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    39
static unsigned line_byte(const char* line, size_t i) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    40
  return unsigned(line[i]) & 0xFF;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    41
}
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    42
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    43
// Verify memset_with_concurrent_readers mimics memset.
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    44
// We don't attempt to verify the concurrent reader case.
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    45
void test_memset_with_concurrent_readers() {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    46
  const size_t chunk_size = 8 * BytesPerWord;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    47
  const unsigned chunk_count = 4;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    48
  const size_t block_size = (chunk_count + 4) * chunk_size;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    49
  char block[block_size];
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    50
  char clear_block[block_size];
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    51
  char set_block[block_size];
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    52
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    53
  // block format:
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    54
  // 0: unused leading chunk
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    55
  // 1: chunk written from start index to end of chunk
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    56
  // ... nchunks fully written chunks
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    57
  // N: chunk written from start of chunk to end index
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    58
  // N+1: unused trailing chunk
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    59
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    60
  const int clear_value = 0;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    61
  const int set_value = 0xAC;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    62
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    63
  memset(clear_block, clear_value, block_size);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    64
  memset(set_block, set_value, block_size);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    65
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    66
  for (unsigned nchunks = 0; nchunks <= chunk_count; ++nchunks) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    67
    for (size_t start = 1; start <= chunk_size; ++start) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    68
      for (size_t end = 0; end <= chunk_size; ++end) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    69
        size_t set_start = chunk_size + start;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    70
        size_t set_end = (2 + nchunks) * chunk_size + end;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    71
        size_t set_size = set_end - set_start;
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    72
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    73
        memset(block, clear_value, block_size);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    74
        memset_with_concurrent_readers(&block[set_start], set_value, set_size);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    75
        bool head_clear = !memcmp(clear_block, block, set_start);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    76
        bool middle_set = !memcmp(set_block, block + set_start, set_size);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    77
        bool tail_clear = !memcmp(clear_block, block + set_end, block_size - set_end);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    78
        if (!(head_clear && middle_set && tail_clear)) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    79
          tty->print_cr("*** memset_with_concurrent_readers failed: "
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    80
                        "set start " SIZE_FORMAT ", set end " SIZE_FORMAT,
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    81
                        set_start, set_end);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    82
          for (unsigned chunk = 0; chunk < (block_size / chunk_size); ++chunk) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    83
            for (unsigned line = 0; line < (chunk_size / BytesPerWord); ++line) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    84
              const char* lp = &block[chunk * chunk_size + line * BytesPerWord];
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    85
              tty->print_cr("%d,%d: %2x %2x  %2x %2x  %2x %2x  %2x %2x",
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    86
                            chunk, line,
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    87
                            line_byte(lp, 0), line_byte(lp, 1),
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    88
                            line_byte(lp, 2), line_byte(lp, 3),
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    89
                            line_byte(lp, 4), line_byte(lp, 5),
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    90
                            line_byte(lp, 6), line_byte(lp, 7));
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    91
            }
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    92
          }
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    93
          assert(head_clear, "leading byte not clear");
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    94
          assert(middle_set, "memset byte not set");
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    95
          assert(tail_clear, "trailing bye not clear");
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    96
        }
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    97
      }
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    98
    }
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
    99
  }
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
   100
}
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
   101
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
   102
#endif // end unit test
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
   103
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents:
diff changeset
   104
#endif // INCLUDE_ALL_GCS