src/hotspot/share/memory/archiveUtils.hpp
author iklam
Wed, 13 Nov 2019 16:36:54 -0800
changeset 59070 22ee476cc664
permissions -rw-r--r--
8231610: Relocate the CDS archive if it cannot be mapped to the requested address Reviewed-by: jiangli, coleenp, ccheung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59070
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     1
/*
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     4
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     8
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    13
 * accompanied this code).
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    14
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    18
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    21
 * questions.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    22
 *
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    23
 */
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    24
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    25
#ifndef SHARE_MEMORY_ARCHIVEUTILS_HPP
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    26
#define SHARE_MEMORY_ARCHIVEUTILS_HPP
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    27
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    28
#include "logging/log.hpp"
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    29
#include "runtime/arguments.hpp"
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    30
#include "utilities/bitMap.hpp"
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    31
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    32
// ArchivePtrMarker is used to mark the location of pointers embedded in a CDS archive. E.g., when an
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    33
// InstanceKlass k is dumped, we mark the location of the k->_name pointer by effectively calling
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    34
// mark_pointer(/*ptr_loc=*/&k->_name). It's required that (_prt_base <= ptr_loc < _ptr_end). _ptr_base is
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    35
// fixed, but _ptr_end can be expanded as more objects are dumped.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    36
class ArchivePtrMarker : AllStatic {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    37
  static CHeapBitMap* _ptrmap;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    38
  static address*     _ptr_base;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    39
  static address*     _ptr_end;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    40
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    41
  // Once _ptrmap is compacted, we don't allow bit marking anymore. This is to
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    42
  // avoid unintentional copy operations after the bitmap has been finalized and written.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    43
  static bool         _compacted;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    44
public:
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    45
  static void initialize(CHeapBitMap* ptrmap, address* ptr_base, address* ptr_end);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    46
  static void mark_pointer(address* ptr_loc);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    47
  static void compact(address relocatable_base, address relocatable_end);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    48
  static void compact(size_t max_non_null_offset);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    49
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    50
  template <typename T>
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    51
  static void mark_pointer(T* ptr_loc) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    52
    mark_pointer((address*)ptr_loc);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    53
  }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    54
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    55
  static void expand_ptr_end(address *new_ptr_end) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    56
    assert(_ptr_end <= new_ptr_end, "must be");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    57
    _ptr_end = new_ptr_end;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    58
  }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    59
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    60
  static CHeapBitMap* ptrmap() {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    61
    return _ptrmap;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    62
  }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    63
};
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    64
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    65
// SharedDataRelocator is used to shift pointers in the CDS archive.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    66
//
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    67
// The CDS archive is basically a contiguous block of memory (divided into several regions)
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    68
// that contains multiple objects. The objects may contain direct pointers that point to other objects
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    69
// within the archive (e.g., InstanceKlass::_name points to a Symbol in the archive). During dumping, we
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    70
// built a bitmap that marks the locations of all these pointers (using ArchivePtrMarker, see comments above).
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    71
//
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    72
// The contents of the archive assumes that it’s mapped at the default SharedBaseAddress (e.g. 0x800000000).
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    73
// If the archive ends up being mapped at a different address (e.g. 0x810000000), SharedDataRelocator
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    74
// is used to shift each marked pointer by a delta (0x10000000 in this example), so that it points to
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    75
// the actually mapped location of the target object.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    76
template <bool COMPACTING>
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    77
class SharedDataRelocator: public BitMapClosure {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    78
  // for all (address** p), where (is_marked(p) && _patch_base <= p && p < _patch_end) { *p += delta; }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    79
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    80
  // Patch all pointers within this region that are marked.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    81
  address* _patch_base;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    82
  address* _patch_end;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    83
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    84
  // Before patching, all pointers must point to this region.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    85
  address _valid_old_base;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    86
  address _valid_old_end;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    87
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    88
  // After patching, all pointers must point to this region.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    89
  address _valid_new_base;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    90
  address _valid_new_end;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    91
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    92
  // How much to relocate for each pointer.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    93
  intx _delta;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    94
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    95
  // The following fields are used only when COMPACTING == true;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    96
  // The highest offset (inclusive) in the bitmap that contains a non-null pointer.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    97
  // This is used at dump time to reduce the size of the bitmap (which may have been over-allocated).
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    98
  size_t _max_non_null_offset;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
    99
  CHeapBitMap* _ptrmap;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   100
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   101
 public:
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   102
  SharedDataRelocator(address* patch_base, address* patch_end,
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   103
                      address valid_old_base, address valid_old_end,
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   104
                      address valid_new_base, address valid_new_end, intx delta,
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   105
                      CHeapBitMap* ptrmap = NULL) :
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   106
    _patch_base(patch_base), _patch_end(patch_end),
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   107
    _valid_old_base(valid_old_base), _valid_old_end(valid_old_end),
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   108
    _valid_new_base(valid_new_base), _valid_new_end(valid_new_end),
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   109
    _delta(delta) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   110
    log_debug(cds, reloc)("SharedDataRelocator::_patch_base     = " PTR_FORMAT, p2i(_patch_base));
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   111
    log_debug(cds, reloc)("SharedDataRelocator::_patch_end      = " PTR_FORMAT, p2i(_patch_end));
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   112
    log_debug(cds, reloc)("SharedDataRelocator::_valid_old_base = " PTR_FORMAT, p2i(_valid_old_base));
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   113
    log_debug(cds, reloc)("SharedDataRelocator::_valid_old_end  = " PTR_FORMAT, p2i(_valid_old_end));
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   114
    log_debug(cds, reloc)("SharedDataRelocator::_valid_new_base = " PTR_FORMAT, p2i(_valid_new_base));
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   115
    log_debug(cds, reloc)("SharedDataRelocator::_valid_new_end  = " PTR_FORMAT, p2i(_valid_new_end));
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   116
    if (COMPACTING) {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   117
      assert(ptrmap != NULL, "must be");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   118
      _max_non_null_offset = 0;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   119
      _ptrmap = ptrmap;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   120
    } else {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   121
      // Don't touch the _max_non_null_offset and _ptrmap fields. Hopefully a good C++ compiler can
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   122
      // elide them.
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   123
      assert(ptrmap == NULL, "must be");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   124
    }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   125
  }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   126
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   127
  size_t max_non_null_offset() {
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   128
    assert(COMPACTING, "must be");
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   129
    return _max_non_null_offset;
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   130
  }
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   131
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   132
  inline bool do_bit(size_t offset);
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   133
};
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   134
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   135
22ee476cc664 8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff changeset
   136
#endif // SHARE_MEMORY_ARCHIVEUTILS_HPP