src/hotspot/share/gc/z/zForwardingTable.cpp
changeset 54163 790679f86a51
parent 54162 f344a0c6e19e
child 58809 44dc3d796110
equal deleted inserted replaced
54162:f344a0c6e19e 54163:790679f86a51
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 #include "precompiled.hpp"
    24 #include "precompiled.hpp"
    25 #include "gc/z/zForwarding.hpp"
    25 #include "gc/z/zAddress.inline.hpp"
       
    26 #include "gc/z/zForwarding.inline.hpp"
    26 #include "gc/z/zForwardingTable.inline.hpp"
    27 #include "gc/z/zForwardingTable.inline.hpp"
    27 #include "gc/z/zGranuleMap.inline.hpp"
    28 #include "gc/z/zGranuleMap.inline.hpp"
    28 #include "utilities/debug.hpp"
    29 #include "utilities/debug.hpp"
    29 
    30 
    30 ZForwardingTable::ZForwardingTable() :
    31 ZForwardingTable::ZForwardingTable() :
    31     _map() {}
    32     _map() {}
    32 
    33 
    33 void ZForwardingTable::insert(uintptr_t start,
    34 void ZForwardingTable::insert(ZForwarding* forwarding) {
    34                               size_t size,
    35   const uintptr_t addr = ZAddress::good(forwarding->start());
    35                               size_t object_alignment_shift,
    36   const size_t size = forwarding->size();
    36                               uint32_t live_objects) {
       
    37   // Allocate forwarding
       
    38   ZForwarding* const forwarding = ZForwarding::create(start,
       
    39                                                       object_alignment_shift,
       
    40                                                       live_objects);
       
    41 
    37 
    42   // Insert into forwarding table
       
    43   const uintptr_t addr = ZAddress::good(start);
       
    44   assert(get(addr) == NULL, "Invalid entry");
    38   assert(get(addr) == NULL, "Invalid entry");
    45   _map.put(addr, size, forwarding);
    39   _map.put(addr, size, forwarding);
    46 }
    40 }
    47 
    41 
    48 void ZForwardingTable::clear() {
    42 void ZForwardingTable::remove(ZForwarding* forwarding) {
    49   ZForwarding* prev_forwarding = NULL;
    43   const uintptr_t addr = ZAddress::good(forwarding->start());
       
    44   const size_t size = forwarding->size();
    50 
    45 
    51   // Clear and destroy all non-NULL entries
    46   assert(get(addr) == forwarding, "Invalid entry");
    52   ZGranuleMapIterator<ZForwarding*> iter(&_map);
    47   _map.put(addr, size, NULL);
    53   for (ZForwarding** entry; iter.next(&entry);) {
       
    54     ZForwarding* const forwarding = *entry;
       
    55     if (forwarding == NULL) {
       
    56       // Skip entry
       
    57       continue;
       
    58     }
       
    59 
       
    60     // Clear entry
       
    61     *entry = NULL;
       
    62 
       
    63     // More than one entry can point to the same
       
    64     // forwarding. Make sure we only destroy it once.
       
    65     if (forwarding != prev_forwarding) {
       
    66       ZForwarding::destroy(forwarding);
       
    67       prev_forwarding = forwarding;
       
    68     }
       
    69   }
       
    70 }
    48 }