src/hotspot/share/gc/z/zMarkStackEntry.hpp
author pliden
Tue, 12 Jun 2018 17:40:28 +0200
changeset 50525 767cdb97f103
child 50875 2217b2fc29ea
permissions -rw-r--r--
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental) Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke Contributed-by: per.liden@oracle.com, stefan.karlsson@oracle.com, erik.osterlund@oracle.com, mikael.gerdin@oracle.com, kim.barrett@oracle.com, nils.eliasson@oracle.com, rickard.backman@oracle.com, rwestrel@redhat.com, coleen.phillimore@oracle.com, robbin.ehn@oracle.com, gerard.ziemski@oracle.com, hugh.wilkinson@intel.com, sandhya.viswanathan@intel.com, bill.npo.wheeler@intel.com, vinay.k.awasthi@intel.com, yasuenag@gmail.com

/*
 * Copyright (c) 2017, 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_GC_Z_ZMARKSTACKENTRY_HPP
#define SHARE_GC_Z_ZMARKSTACKENTRY_HPP

#include "gc/z/zBitField.hpp"
#include "memory/allocation.hpp"

//
// Mark stack entry layout
// -----------------------
//
//  Object entry
//  ------------
//
//   6
//   3                                                                   2 1 0
//  +---------------------------------------------------------------------+-+-+
//  |11111111 11111111 11111111 11111111 11111111 11111111 11111111 111111|1|1|
//  +---------------------------------------------------------------------+-+-+
//  |                                                                     | |
//  |                                      1-1 Partial Array Flag (1-bit) * |
//  |                                                                       |
//  |                                                0-0 Final Flag (1-bit) *
//  |
//  * 63-2 Object Address (62-bits)
//
//
//  Partial array entry
//  -------------------
//
//   6                                 3  3
//   3                                 2  1                               2 1 0
//  +------------------------------------+---------------------------------+-+-+
//  |11111111 11111111 11111111 11111111 |11111111 11111111 11111111 111111|1|1|
//  +------------------------------------+---------------------------------+-+-+
//  |                                    |                                 | |
//  |                                    |  1-1 Partial Array Flag (1-bit) * |
//  |                                    |                                   |
//  |                                    |            0-0 Final Flag (1-bit) *
//  |                                    |
//  |                                    * 31-2 Partial Array Length (30-bits)
//  |
//  * 63-32 Partial Array Address Offset (32-bits)
//

class ZMarkStackEntry  {
private:
  typedef ZBitField<uint64_t, bool,      0,  1>  field_finalizable;
  typedef ZBitField<uint64_t, bool,      1,  1>  field_partial_array;
  typedef ZBitField<uint64_t, uintptr_t, 2,  62> field_object_address;
  typedef ZBitField<uint64_t, size_t,    2,  30> field_partial_array_length;
  typedef ZBitField<uint64_t, size_t,    32, 32> field_partial_array_offset;

  uint64_t _entry;

public:
  ZMarkStackEntry() {
    // This constructor is intentionally left emtpy and does not initialize
    // _entry to allow it to be optimized out when instantiating ZMarkStack,
    // which has a long array of ZMarkStackEntry elements, but doesn't care
    // what _entry is initialized to.
  }

  ZMarkStackEntry(uintptr_t object_address, bool finalizable) :
      _entry(field_object_address::encode(object_address) |
             field_partial_array::encode(false) |
             field_finalizable::encode(finalizable)) {}

  ZMarkStackEntry(size_t partial_array_offset, size_t partial_array_length, bool finalizable) :
      _entry(field_partial_array_offset::encode(partial_array_offset) |
             field_partial_array_length::encode(partial_array_length) |
             field_partial_array::encode(true) |
             field_finalizable::encode(finalizable)) {}

  bool finalizable() const {
    return field_finalizable::decode(_entry);
  }

  bool partial_array() const {
    return field_partial_array::decode(_entry);
  }

  size_t partial_array_offset() const {
    return field_partial_array_offset::decode(_entry);
  }

  size_t partial_array_length() const {
    return field_partial_array_length::decode(_entry);
  }

  uintptr_t object_address() const {
    return field_object_address::decode(_entry);
  }
};

#endif // SHARE_GC_Z_ZMARKSTACKENTRY_HPP