--- /dev/null 2019-02-25 13:26:02.045529497 -0800 +++ new/src/hotspot/share/memory/archiveUtils.hpp 2019-10-10 17:16:51.046707219 -0700 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_MEMORY_SHAREDDATARELOCATOR_HPP +#define SHARE_MEMORY_SHAREDDATARELOCATOR_HPP + +#include "logging/log.hpp" +#include "utilities/bitMap.inline.hpp" + +class ArchivePtrMarker : AllStatic { + static CHeapBitMap* _ptrmap; + static address* _ptr_base; + static address* _ptr_end; + static size_t _max_index; + static bool _compacted; +public: + static void initialize(CHeapBitMap* ptrmap, address* ptr_base, address* ptr_end); + static void mark_pointer(address* ptr_loc); + static void compact(address relocatable_base, address relocatable_end); + + template + static void mark_pointer(T* ptr_loc) { + mark_pointer((address*)ptr_loc); + } + + static void expand_ptr_end(address *new_ptr_end) { + assert(_ptr_end <= new_ptr_end, "must be"); + _ptr_end = new_ptr_end; + } + + static CHeapBitMap* ptrmap() { + return _ptrmap; + } +}; + +class SharedDataRelocator: public BitMapClosure { + // for all (address** p), where (is_marked(p) && _patch_base <= p && p < _patch_end) { *p += delta; } + + // Patch all pointers within this region that are marked. + address* _patch_base; + address* _patch_end; + + // Debug-only: before patching, all pointers must point to this region. + address _valid_old_base; + address _valid_old_end; + + // Debug-only: after patching, all pointers must point to this region. + address _valid_new_base; + address _valid_new_end; + + // How much to relocate for each pointer. + intx _delta; + public: + SharedDataRelocator(address* patch_base, address* patch_end, + address valid_old_base, address valid_old_end, + address valid_new_base, address valid_new_end, intx delta) : + _patch_base(patch_base), _patch_end(patch_end), + _valid_old_base(valid_old_base), _valid_old_end(valid_old_end), + _valid_new_base(valid_new_base), _valid_new_end(valid_new_end), + _delta(delta) { + log_debug(cds, reloc)("SharedDataRelocator::_patch_base = " PTR_FORMAT, p2i(_patch_base)); + log_debug(cds, reloc)("SharedDataRelocator::_patch_end = " PTR_FORMAT, p2i(_patch_end)); + log_debug(cds, reloc)("SharedDataRelocator::_valid_old_base = " PTR_FORMAT, p2i(_valid_old_base)); + log_debug(cds, reloc)("SharedDataRelocator::_valid_old_end = " PTR_FORMAT, p2i(_valid_old_end)); + log_debug(cds, reloc)("SharedDataRelocator::_valid_new_base = " PTR_FORMAT, p2i(_valid_new_base)); + log_debug(cds, reloc)("SharedDataRelocator::_valid_new_end = " PTR_FORMAT, p2i(_valid_new_end)); + } + + bool do_bit(size_t offset) { + address* p = _patch_base + offset; + assert(_patch_base <= p && p < _patch_end, "must be"); + + address old_ptr = *p; + assert(_valid_old_base <= old_ptr && old_ptr < _valid_old_end, "must be"); + + address new_ptr = old_ptr + _delta; + assert(_valid_new_base <= new_ptr && new_ptr < _valid_new_end, "must be"); + + DEBUG_ONLY(log_trace(cds, reloc)("Patch2: @%8d [" PTR_FORMAT "] " PTR_FORMAT " -> " PTR_FORMAT, + (int)offset, p2i(p), p2i(old_ptr), p2i(new_ptr))); + *p = new_ptr; + return true; // keep iterating + } +}; + + +#endif // SHARE_MEMORY_SHAREDDATARELOCATOR_HPP