< prev index next >

src/hotspot/share/memory/archiveUtils.hpp

Print this page
   1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  27 
  28 #include "logging/log.hpp"
  29 #include "runtime/arguments.hpp"
  30 #include "utilities/bitMap.hpp"
  31 
  32 // ArchivePtrMarker is used to mark the location of pointers embedded in a CDS archive. E.g., when an
  33 // InstanceKlass k is dumped, we mark the location of the k->_name pointer by effectively calling
  34 // mark_pointer(/*ptr_loc=*/&k->_name). It's required that (_prt_base <= ptr_loc < _ptr_end). _ptr_base is
  35 // fixed, but _ptr_end can be expanded as more objects are dumped.
  36 class ArchivePtrMarker : AllStatic {
  37   static CHeapBitMap* _ptrmap;
  38   static address*     _ptr_base;
  39   static address*     _ptr_end;
  40 
  41   // Once _ptrmap is compacted, we don't allow bit marking anymore. This is to
  42   // avoid unintentional copy operations after the bitmap has been finalized and written.
  43   static bool         _compacted;
  44 public:
  45   static void initialize(CHeapBitMap* ptrmap, address* ptr_base, address* ptr_end);
  46   static void mark_pointer(address* ptr_loc);

  47   static void compact(address relocatable_base, address relocatable_end);
  48   static void compact(size_t max_non_null_offset);
  49 
  50   template <typename T>
  51   static void mark_pointer(T* ptr_loc) {
  52     mark_pointer((address*)ptr_loc);






  53   }
  54 
  55   static void expand_ptr_end(address *new_ptr_end) {
  56     assert(_ptr_end <= new_ptr_end, "must be");
  57     _ptr_end = new_ptr_end;
  58   }
  59 
  60   static CHeapBitMap* ptrmap() {
  61     return _ptrmap;
  62   }
  63 };
  64 
  65 // SharedDataRelocator is used to shift pointers in the CDS archive.
  66 //
  67 // The CDS archive is basically a contiguous block of memory (divided into several regions)
  68 // that contains multiple objects. The objects may contain direct pointers that point to other objects
  69 // within the archive (e.g., InstanceKlass::_name points to a Symbol in the archive). During dumping, we
  70 // built a bitmap that marks the locations of all these pointers (using ArchivePtrMarker, see comments above).
  71 //
  72 // The contents of the archive assumes that it’s mapped at the default SharedBaseAddress (e.g. 0x800000000).


   1 /*
   2  * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  27 
  28 #include "logging/log.hpp"
  29 #include "runtime/arguments.hpp"
  30 #include "utilities/bitMap.hpp"
  31 
  32 // ArchivePtrMarker is used to mark the location of pointers embedded in a CDS archive. E.g., when an
  33 // InstanceKlass k is dumped, we mark the location of the k->_name pointer by effectively calling
  34 // mark_pointer(/*ptr_loc=*/&k->_name). It's required that (_prt_base <= ptr_loc < _ptr_end). _ptr_base is
  35 // fixed, but _ptr_end can be expanded as more objects are dumped.
  36 class ArchivePtrMarker : AllStatic {
  37   static CHeapBitMap* _ptrmap;
  38   static address*     _ptr_base;
  39   static address*     _ptr_end;
  40 
  41   // Once _ptrmap is compacted, we don't allow bit marking anymore. This is to
  42   // avoid unintentional copy operations after the bitmap has been finalized and written.
  43   static bool         _compacted;
  44 public:
  45   static void initialize(CHeapBitMap* ptrmap, address* ptr_base, address* ptr_end);
  46   static void mark_pointer(address* ptr_loc);
  47   static void clear_pointer(address* ptr_loc);
  48   static void compact(address relocatable_base, address relocatable_end);
  49   static void compact(size_t max_non_null_offset);
  50 
  51   template <typename T>
  52   static void mark_pointer(T* ptr_loc) {
  53     mark_pointer((address*)ptr_loc);
  54   }
  55 
  56   template <typename T>
  57   static void set_and_mark_pointer(T* ptr_loc, T ptr_value) {
  58     *ptr_loc = ptr_value;
  59     mark_pointer(ptr_loc);
  60   }
  61 
  62   static void expand_ptr_end(address *new_ptr_end) {
  63     assert(_ptr_end <= new_ptr_end, "must be");
  64     _ptr_end = new_ptr_end;
  65   }
  66 
  67   static CHeapBitMap* ptrmap() {
  68     return _ptrmap;
  69   }
  70 };
  71 
  72 // SharedDataRelocator is used to shift pointers in the CDS archive.
  73 //
  74 // The CDS archive is basically a contiguous block of memory (divided into several regions)
  75 // that contains multiple objects. The objects may contain direct pointers that point to other objects
  76 // within the archive (e.g., InstanceKlass::_name points to a Symbol in the archive). During dumping, we
  77 // built a bitmap that marks the locations of all these pointers (using ArchivePtrMarker, see comments above).
  78 //
  79 // The contents of the archive assumes that it’s mapped at the default SharedBaseAddress (e.g. 0x800000000).


< prev index next >