< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahAllocRequest.hpp

Print this page

  1 /*
  2  * Copyright (c) 2018, 2019, Red Hat, Inc. 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 
 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
 27 
 28 #include "memory/allocation.hpp"

 29 
 30 class ShenandoahAllocRequest : StackObj {
 31 public:
 32   enum Type {
 33     _alloc_shared,      // Allocate common, outside of TLAB
 34     _alloc_shared_gc,   // Allocate common, outside of GCLAB
 35     _alloc_tlab,        // Allocate TLAB
 36     _alloc_gclab,       // Allocate GCLAB

 37     _ALLOC_LIMIT
 38   };
 39 
 40   static const char* alloc_type_to_string(Type type) {
 41     switch (type) {
 42       case _alloc_shared:
 43         return "Shared";
 44       case _alloc_shared_gc:
 45         return "Shared GC";
 46       case _alloc_tlab:
 47         return "TLAB";
 48       case _alloc_gclab:
 49         return "GCLAB";


 50       default:
 51         ShouldNotReachHere();
 52         return "";
 53     }
 54   }
 55 
 56 private:
 57   size_t _min_size;
 58   size_t _requested_size;
 59   size_t _actual_size;
 60   Type _alloc_type;

 61 #ifdef ASSERT
 62   bool _actual_size_set;
 63 #endif
 64 
 65   ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type) :
 66           _min_size(_min_size), _requested_size(_requested_size),
 67           _actual_size(0), _alloc_type(_alloc_type)
 68 #ifdef ASSERT
 69           , _actual_size_set(false)
 70 #endif
 71   {}
 72 
 73 public:
 74   static inline ShenandoahAllocRequest for_tlab(size_t min_size, size_t requested_size) {
 75     return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab);
 76   }
 77 
 78   static inline ShenandoahAllocRequest for_gclab(size_t min_size, size_t requested_size) {
 79     return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab);
 80   }
 81 
 82   static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size) {
 83     return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc);




 84   }
 85 
 86   static inline ShenandoahAllocRequest for_shared(size_t requested_size) {
 87     return ShenandoahAllocRequest(0, requested_size, _alloc_shared);
 88   }
 89 
 90   inline size_t size() {
 91     return _requested_size;
 92   }
 93 
 94   inline Type type() {
 95     return _alloc_type;
 96   }
 97 
 98   inline const char* type_string() {
 99     return alloc_type_to_string(_alloc_type);
100   }
101 
102   inline size_t min_size() {
103     assert (is_lab_alloc(), "Only access for LAB allocs");
104     return _min_size;
105   }
106 
107   inline size_t actual_size() {
108     assert (_actual_size_set, "Should be set");
109     return _actual_size;
110   }
111 
112   inline void set_actual_size(size_t v) {
113 #ifdef ASSERT
114     assert (!_actual_size_set, "Should not be set");
115     _actual_size_set = true;
116 #endif
117     _actual_size = v;
118   }
119 
120   inline bool is_mutator_alloc() {
121     switch (_alloc_type) {
122       case _alloc_tlab:
123       case _alloc_shared:
124         return true;
125       case _alloc_gclab:

126       case _alloc_shared_gc:
127         return false;
128       default:
129         ShouldNotReachHere();
130         return false;
131     }
132   }
133 
134   inline bool is_gc_alloc() {
135     switch (_alloc_type) {
136       case _alloc_tlab:
137       case _alloc_shared:
138         return false;
139       case _alloc_gclab:

140       case _alloc_shared_gc:
141         return true;
142       default:
143         ShouldNotReachHere();
144         return false;
145     }
146   }
147 
148   inline bool is_lab_alloc() {
149     switch (_alloc_type) {
150       case _alloc_tlab:
151       case _alloc_gclab:

152         return true;
153       case _alloc_shared:
154       case _alloc_shared_gc:
155         return false;
156       default:
157         ShouldNotReachHere();
158         return false;
159     }
160   }












161 };
162 
163 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP

  1 /*
  2  * Copyright (c) 2018, 2020, Red Hat, Inc. 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 
 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
 27 
 28 #include "memory/allocation.hpp"
 29 #include "gc/shenandoah/mode/shenandoahGenerationalMode.hpp"
 30 
 31 class ShenandoahAllocRequest : StackObj {
 32 public:
 33   enum Type {
 34     _alloc_shared,      // Allocate common, outside of TLAB
 35     _alloc_shared_gc,   // Allocate common, outside of GCLAB/PLAB
 36     _alloc_tlab,        // Allocate TLAB
 37     _alloc_gclab,       // Allocate GCLAB
 38     _alloc_plab,        // Allocate PLAB
 39     _ALLOC_LIMIT
 40   };
 41 
 42   static const char* alloc_type_to_string(Type type) {
 43     switch (type) {
 44       case _alloc_shared:
 45         return "Shared";
 46       case _alloc_shared_gc:
 47         return "Shared GC";
 48       case _alloc_tlab:
 49         return "TLAB";
 50       case _alloc_gclab:
 51         return "GCLAB";
 52       case _alloc_plab:
 53         return "PLAB";
 54       default:
 55         ShouldNotReachHere();
 56         return "";
 57     }
 58   }
 59 
 60 private:
 61   size_t _min_size;
 62   size_t _requested_size;
 63   size_t _actual_size;
 64   Type _alloc_type;
 65   ShenandoahRegionAffiliation const _affiliation;
 66 #ifdef ASSERT
 67   bool _actual_size_set;
 68 #endif
 69 
 70   ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type, ShenandoahRegionAffiliation affiliation) :
 71           _min_size(_min_size), _requested_size(_requested_size),
 72           _actual_size(0), _alloc_type(_alloc_type), _affiliation(affiliation)
 73 #ifdef ASSERT
 74           , _actual_size_set(false)
 75 #endif
 76   {}
 77 
 78 public:
 79   static inline ShenandoahAllocRequest for_tlab(size_t min_size, size_t requested_size) {
 80     return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab, ShenandoahRegionAffiliation::YOUNG_GENERATION);
 81   }
 82 
 83   static inline ShenandoahAllocRequest for_gclab(size_t min_size, size_t requested_size) {
 84     return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab, ShenandoahRegionAffiliation::YOUNG_GENERATION);
 85   }
 86 
 87   static inline ShenandoahAllocRequest for_plab(size_t min_size, size_t requested_size) {
 88     return ShenandoahAllocRequest(min_size, requested_size, _alloc_plab, ShenandoahRegionAffiliation::OLD_GENERATION);
 89   }
 90 
 91   static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size, ShenandoahRegionAffiliation affiliation) {
 92     return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc, affiliation);
 93   }
 94 
 95   static inline ShenandoahAllocRequest for_shared(size_t requested_size) {
 96     return ShenandoahAllocRequest(0, requested_size, _alloc_shared, ShenandoahRegionAffiliation::YOUNG_GENERATION);
 97   }
 98 
 99   inline size_t size() {
100     return _requested_size;
101   }
102 
103   inline Type type() {
104     return _alloc_type;
105   }
106 
107   inline const char* type_string() {
108     return alloc_type_to_string(_alloc_type);
109   }
110 
111   inline size_t min_size() {
112     assert (is_lab_alloc(), "Only access for LAB allocs");
113     return _min_size;
114   }
115 
116   inline size_t actual_size() {
117     assert (_actual_size_set, "Should be set");
118     return _actual_size;
119   }
120 
121   inline void set_actual_size(size_t v) {
122 #ifdef ASSERT
123     assert (!_actual_size_set, "Should not be set");
124     _actual_size_set = true;
125 #endif
126     _actual_size = v;
127   }
128 
129   inline bool is_mutator_alloc() {
130     switch (_alloc_type) {
131       case _alloc_tlab:
132       case _alloc_shared:
133         return true;
134       case _alloc_gclab:
135       case _alloc_plab:
136       case _alloc_shared_gc:
137         return false;
138       default:
139         ShouldNotReachHere();
140         return false;
141     }
142   }
143 
144   inline bool is_gc_alloc() {
145     switch (_alloc_type) {
146       case _alloc_tlab:
147       case _alloc_shared:
148         return false;
149       case _alloc_gclab:
150       case _alloc_plab:
151       case _alloc_shared_gc:
152         return true;
153       default:
154         ShouldNotReachHere();
155         return false;
156     }
157   }
158 
159   inline bool is_lab_alloc() {
160     switch (_alloc_type) {
161       case _alloc_tlab:
162       case _alloc_gclab:
163       case _alloc_plab:
164         return true;
165       case _alloc_shared:
166       case _alloc_shared_gc:
167         return false;
168       default:
169         ShouldNotReachHere();
170         return false;
171     }
172   }
173 
174   bool is_old() {
175     return _affiliation == OLD_GENERATION;
176   }
177 
178   bool is_young() {
179     return _affiliation == YOUNG_GENERATION;
180   }
181 
182   ShenandoahRegionAffiliation affiliation() const {
183     return _affiliation;
184   }
185 };
186 
187 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
< prev index next >