src/hotspot/share/gc/z/zForwarding.cpp
changeset 54162 f344a0c6e19e
parent 52799 cd19c580ba9c
child 54163 790679f86a51
equal deleted inserted replaced
54161:349843ebb209 54162:f344a0c6e19e
       
     1 /*
       
     2  * Copyright (c) 2015, 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  */
       
    23 
       
    24 #include "precompiled.hpp"
       
    25 #include "gc/z/zForwarding.inline.hpp"
       
    26 #include "gc/z/zUtils.inline.hpp"
       
    27 #include "memory/allocation.hpp"
       
    28 #include "utilities/debug.hpp"
       
    29 
       
    30 ZForwarding::ZForwarding(uintptr_t start, size_t object_alignment_shift, uint32_t nentries) :
       
    31     _start(start),
       
    32     _object_alignment_shift(object_alignment_shift),
       
    33     _nentries(nentries),
       
    34     _refcount(1),
       
    35     _pinned(false) {}
       
    36 
       
    37 ZForwarding* ZForwarding::create(uintptr_t start, size_t object_alignment_shift, uint32_t live_objects) {
       
    38   assert(live_objects > 0, "Invalid value");
       
    39 
       
    40   // Allocate table for linear probing. The size of the table must be
       
    41   // a power of two to allow for quick and inexpensive indexing/masking.
       
    42   // The table is sized to have a load factor of 50%, i.e. sized to have
       
    43   // double the number of entries actually inserted.
       
    44   const uint32_t nentries = ZUtils::round_up_power_of_2(live_objects * 2);
       
    45 
       
    46   const size_t size = sizeof(ZForwarding) + (sizeof(ZForwardingEntry) * nentries);
       
    47   uint8_t* const addr = NEW_C_HEAP_ARRAY(uint8_t, size, mtGC);
       
    48   ZForwardingEntry* const entries = ::new (addr + sizeof(ZForwarding)) ZForwardingEntry[nentries];
       
    49   ZForwarding* const forwarding = ::new (addr) ZForwarding(start, object_alignment_shift, nentries);
       
    50   return forwarding;
       
    51 }
       
    52 
       
    53 void ZForwarding::destroy(ZForwarding* forwarding) {
       
    54   FREE_C_HEAP_ARRAY(uint8_t, forwarding);
       
    55 }
       
    56 
       
    57 void ZForwarding::verify(uint32_t object_max_count, uint32_t live_objects) const {
       
    58   uint32_t count = 0;
       
    59 
       
    60   for (ZForwardingCursor i = 0; i < _nentries; i++) {
       
    61     const ZForwardingEntry entry = at(&i);
       
    62     if (entry.is_empty()) {
       
    63       // Skip empty entries
       
    64       continue;
       
    65     }
       
    66 
       
    67     // Check from index
       
    68     guarantee(entry.from_index() < object_max_count, "Invalid from index");
       
    69 
       
    70     // Check for duplicates
       
    71     for (ZForwardingCursor j = i + 1; j < _nentries; j++) {
       
    72       const ZForwardingEntry other = at(&j);
       
    73       guarantee(entry.from_index() != other.from_index(), "Duplicate from");
       
    74       guarantee(entry.to_offset() != other.to_offset(), "Duplicate to");
       
    75     }
       
    76 
       
    77     count++;
       
    78   }
       
    79 
       
    80   // Check number of non-null entries
       
    81   guarantee(live_objects == count, "Count mismatch");
       
    82 }