src/share/vm/gc_implementation/g1/heapRegionType.hpp

changeset 7195
c02ec279b062
child 9861
a248d0be1309
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionType.hpp	Tue Sep 16 14:27:40 2014 +0200
     1.3 @@ -0,0 +1,134 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONTYPE_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONTYPE_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +
    1.33 +#define hrt_assert_is_valid(tag) \
    1.34 +  assert(is_valid((tag)), err_msg("invalid HR type: %u", (uint) (tag)))
    1.35 +
    1.36 +class HeapRegionType VALUE_OBJ_CLASS_SPEC {
    1.37 +private:
    1.38 +  // We encode the value of the heap region type so the generation can be
    1.39 +  // determined quickly. The tag is split into two parts:
    1.40 +  //
    1.41 +  //   major type (young, humongous)                         : top N-1 bits
    1.42 +  //   minor type (eden / survivor, starts / cont hum, etc.) : bottom 1 bit
    1.43 +  //
    1.44 +  // If there's need to increase the number of minor types in the
    1.45 +  // future, we'll have to increase the size of the latter and hence
    1.46 +  // decrease the size of the former.
    1.47 +  //
    1.48 +  // 0000 0 [ 0] Free
    1.49 +  //
    1.50 +  // 0001 0      Young Mask
    1.51 +  // 0001 0 [ 2] Eden
    1.52 +  // 0001 1 [ 3] Survivor
    1.53 +  //
    1.54 +  // 0010 0      Humongous Mask
    1.55 +  // 0010 0 [ 4] Humongous Starts
    1.56 +  // 0010 1 [ 5] Humongous Continues
    1.57 +  //
    1.58 +  // 01000 [ 8] Old
    1.59 +  typedef enum {
    1.60 +    FreeTag       = 0,
    1.61 +
    1.62 +    YoungMask     = 2,
    1.63 +    EdenTag       = YoungMask,
    1.64 +    SurvTag       = YoungMask + 1,
    1.65 +
    1.66 +    HumMask       = 4,
    1.67 +    HumStartsTag  = HumMask,
    1.68 +    HumContTag    = HumMask + 1,
    1.69 +
    1.70 +    OldTag        = 8
    1.71 +  } Tag;
    1.72 +
    1.73 +  volatile Tag _tag;
    1.74 +
    1.75 +  static bool is_valid(Tag tag);
    1.76 +
    1.77 +  Tag get() const {
    1.78 +    hrt_assert_is_valid(_tag);
    1.79 +    return _tag;
    1.80 +  }
    1.81 +
    1.82 +  // Sets the type to 'tag'.
    1.83 +  void set(Tag tag) {
    1.84 +    hrt_assert_is_valid(tag);
    1.85 +    hrt_assert_is_valid(_tag);
    1.86 +    _tag = tag;
    1.87 +  }
    1.88 +
    1.89 +  // Sets the type to 'tag', expecting the type to be 'before'. This
    1.90 +  // is available for when we want to add sanity checking to the type
    1.91 +  // transition.
    1.92 +  void set_from(Tag tag, Tag before) {
    1.93 +    hrt_assert_is_valid(tag);
    1.94 +    hrt_assert_is_valid(before);
    1.95 +    hrt_assert_is_valid(_tag);
    1.96 +    assert(_tag == before,
    1.97 +           err_msg("HR tag: %u, expected: %u new tag; %u", _tag, before, tag));
    1.98 +    _tag = tag;
    1.99 +  }
   1.100 +
   1.101 +public:
   1.102 +  // Queries
   1.103 +
   1.104 +  bool is_free() const { return get() == FreeTag; }
   1.105 +
   1.106 +  bool is_young()    const { return (get() & YoungMask) != 0; }
   1.107 +  bool is_eden()     const { return get() == EdenTag;  }
   1.108 +  bool is_survivor() const { return get() == SurvTag;  }
   1.109 +
   1.110 +  bool is_humongous()           const { return (get() & HumMask) != 0; }
   1.111 +  bool is_starts_humongous()    const { return get() == HumStartsTag;  }
   1.112 +  bool is_continues_humongous() const { return get() == HumContTag;    }
   1.113 +
   1.114 +  bool is_old() const { return get() == OldTag; }
   1.115 +
   1.116 +  // Setters
   1.117 +
   1.118 +  void set_free() { set(FreeTag); }
   1.119 +
   1.120 +  void set_eden()        { set_from(EdenTag, FreeTag); }
   1.121 +  void set_eden_pre_gc() { set_from(EdenTag, SurvTag); }
   1.122 +  void set_survivor()    { set_from(SurvTag, FreeTag); }
   1.123 +
   1.124 +  void set_starts_humongous()    { set_from(HumStartsTag, FreeTag); }
   1.125 +  void set_continues_humongous() { set_from(HumContTag,   FreeTag); }
   1.126 +
   1.127 +  void set_old() { set(OldTag); }
   1.128 +
   1.129 +  // Misc
   1.130 +
   1.131 +  const char* get_str() const;
   1.132 +  const char* get_short_str() const;
   1.133 +
   1.134 +  HeapRegionType() : _tag(FreeTag) { hrt_assert_is_valid(_tag); }
   1.135 +};
   1.136 +
   1.137 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONTYPE_HPP

mercurial