1 /*
   2  * Copyright (c) 2017, 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 #ifndef SHARE_GC_Z_ZMARKSTACKENTRY_HPP
  25 #define SHARE_GC_Z_ZMARKSTACKENTRY_HPP
  26 
  27 #include "gc/z/zBitField.hpp"
  28 #include "memory/allocation.hpp"
  29 
  30 //
  31 // Mark stack entry layout
  32 // -----------------------
  33 //
  34 //  Object entry
  35 //  ------------
  36 //
  37 //   6
  38 //   3                                                                  3 2 1 0
  39 //  +--------------------------------------------------------------------+-+-+-+
  40 //  |11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111|1|1|1|
  41 //  +--------------------------------------------------------------------+-+-+-+
  42 //  |                                                                    | | |
  43 //  |                                            2-2 Follow Flag (1-bit) * | |
  44 //  |                                                                      | |
  45 //  |                                       1-1 Partial Array Flag (1-bit) * |
  46 //  |                                                                        |
  47 //  |                                                 0-0 Final Flag (1-bit) *
  48 //  |
  49 //  * 63-3 Object Address (62-bits)
  50 //
  51 //
  52 //  Partial array entry
  53 //  -------------------
  54 //
  55 //   6                                 3  3
  56 //   3                                 2  1                               2 1 0
  57 //  +------------------------------------+---------------------------------+-+-+
  58 //  |11111111 11111111 11111111 11111111 |11111111 11111111 11111111 111111|1|1|
  59 //  +------------------------------------+---------------------------------+-+-+
  60 //  |                                    |                                 | |
  61 //  |                                    |  1-1 Partial Array Flag (1-bit) * |
  62 //  |                                    |                                   |
  63 //  |                                    |            0-0 Final Flag (1-bit) *
  64 //  |                                    |
  65 //  |                                    * 31-2 Partial Array Length (30-bits)
  66 //  |
  67 //  * 63-32 Partial Array Address Offset (32-bits)
  68 //
  69 
  70 class ZMarkStackEntry  {
  71 private:
  72   typedef ZBitField<uint64_t, bool,      0,  1>  field_finalizable;
  73   typedef ZBitField<uint64_t, bool,      1,  1>  field_partial_array;
  74   typedef ZBitField<uint64_t, bool,      2,  1>  field_follow;
  75   typedef ZBitField<uint64_t, uintptr_t, 3,  61> field_object_address;
  76   typedef ZBitField<uint64_t, size_t,    2,  30> field_partial_array_length;
  77   typedef ZBitField<uint64_t, size_t,    32, 32> field_partial_array_offset;
  78 
  79   uint64_t _entry;
  80 
  81 public:
  82   ZMarkStackEntry() {
  83     // This constructor is intentionally left empty and does not initialize
  84     // _entry to allow it to be optimized out when instantiating ZMarkStack,
  85     // which has a long array of ZMarkStackEntry elements, but doesn't care
  86     // what _entry is initialized to.
  87   }
  88 
  89   ZMarkStackEntry(uintptr_t object_address, bool follow, bool finalizable) :
  90       _entry(field_object_address::encode(object_address) |
  91              field_follow::encode(follow) |
  92              field_partial_array::encode(false) |
  93              field_finalizable::encode(finalizable)) {}
  94 
  95   ZMarkStackEntry(size_t partial_array_offset, size_t partial_array_length, bool finalizable) :
  96       _entry(field_partial_array_offset::encode(partial_array_offset) |
  97              field_partial_array_length::encode(partial_array_length) |
  98              field_partial_array::encode(true) |
  99              field_finalizable::encode(finalizable)) {}
 100 
 101   bool finalizable() const {
 102     return field_finalizable::decode(_entry);
 103   }
 104 
 105   bool partial_array() const {
 106     return field_partial_array::decode(_entry);
 107   }
 108 
 109   size_t partial_array_offset() const {
 110     return field_partial_array_offset::decode(_entry);
 111   }
 112 
 113   size_t partial_array_length() const {
 114     return field_partial_array_length::decode(_entry);
 115   }
 116 
 117   bool follow() const {
 118     return field_follow::decode(_entry);
 119   }
 120 
 121   uintptr_t object_address() const {
 122     return field_object_address::decode(_entry);
 123   }
 124 };
 125 
 126 #endif // SHARE_GC_Z_ZMARKSTACKENTRY_HPP