src/hotspot/share/gc/z/zMarkStackEntry.hpp
changeset 50525 767cdb97f103
child 50875 2217b2fc29ea
equal deleted inserted replaced
50524:04f4e983c2f7 50525:767cdb97f103
       
     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                                                                   2 1 0
       
    39 //  +---------------------------------------------------------------------+-+-+
       
    40 //  |11111111 11111111 11111111 11111111 11111111 11111111 11111111 111111|1|1|
       
    41 //  +---------------------------------------------------------------------+-+-+
       
    42 //  |                                                                     | |
       
    43 //  |                                      1-1 Partial Array Flag (1-bit) * |
       
    44 //  |                                                                       |
       
    45 //  |                                                0-0 Final Flag (1-bit) *
       
    46 //  |
       
    47 //  * 63-2 Object Address (62-bits)
       
    48 //
       
    49 //
       
    50 //  Partial array entry
       
    51 //  -------------------
       
    52 //
       
    53 //   6                                 3  3
       
    54 //   3                                 2  1                               2 1 0
       
    55 //  +------------------------------------+---------------------------------+-+-+
       
    56 //  |11111111 11111111 11111111 11111111 |11111111 11111111 11111111 111111|1|1|
       
    57 //  +------------------------------------+---------------------------------+-+-+
       
    58 //  |                                    |                                 | |
       
    59 //  |                                    |  1-1 Partial Array Flag (1-bit) * |
       
    60 //  |                                    |                                   |
       
    61 //  |                                    |            0-0 Final Flag (1-bit) *
       
    62 //  |                                    |
       
    63 //  |                                    * 31-2 Partial Array Length (30-bits)
       
    64 //  |
       
    65 //  * 63-32 Partial Array Address Offset (32-bits)
       
    66 //
       
    67 
       
    68 class ZMarkStackEntry  {
       
    69 private:
       
    70   typedef ZBitField<uint64_t, bool,      0,  1>  field_finalizable;
       
    71   typedef ZBitField<uint64_t, bool,      1,  1>  field_partial_array;
       
    72   typedef ZBitField<uint64_t, uintptr_t, 2,  62> field_object_address;
       
    73   typedef ZBitField<uint64_t, size_t,    2,  30> field_partial_array_length;
       
    74   typedef ZBitField<uint64_t, size_t,    32, 32> field_partial_array_offset;
       
    75 
       
    76   uint64_t _entry;
       
    77 
       
    78 public:
       
    79   ZMarkStackEntry() {
       
    80     // This constructor is intentionally left emtpy and does not initialize
       
    81     // _entry to allow it to be optimized out when instantiating ZMarkStack,
       
    82     // which has a long array of ZMarkStackEntry elements, but doesn't care
       
    83     // what _entry is initialized to.
       
    84   }
       
    85 
       
    86   ZMarkStackEntry(uintptr_t object_address, bool finalizable) :
       
    87       _entry(field_object_address::encode(object_address) |
       
    88              field_partial_array::encode(false) |
       
    89              field_finalizable::encode(finalizable)) {}
       
    90 
       
    91   ZMarkStackEntry(size_t partial_array_offset, size_t partial_array_length, bool finalizable) :
       
    92       _entry(field_partial_array_offset::encode(partial_array_offset) |
       
    93              field_partial_array_length::encode(partial_array_length) |
       
    94              field_partial_array::encode(true) |
       
    95              field_finalizable::encode(finalizable)) {}
       
    96 
       
    97   bool finalizable() const {
       
    98     return field_finalizable::decode(_entry);
       
    99   }
       
   100 
       
   101   bool partial_array() const {
       
   102     return field_partial_array::decode(_entry);
       
   103   }
       
   104 
       
   105   size_t partial_array_offset() const {
       
   106     return field_partial_array_offset::decode(_entry);
       
   107   }
       
   108 
       
   109   size_t partial_array_length() const {
       
   110     return field_partial_array_length::decode(_entry);
       
   111   }
       
   112 
       
   113   uintptr_t object_address() const {
       
   114     return field_object_address::decode(_entry);
       
   115   }
       
   116 };
       
   117 
       
   118 #endif // SHARE_GC_Z_ZMARKSTACKENTRY_HPP