< 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, 2019, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
 28 
 29 #include "gc/shenandoah/shenandoahAffiliation.hpp"
 30 #include "memory/allocation.hpp"
 31 
 32 class ShenandoahAllocRequest : StackObj {
 33 public:
 34   enum Type {
 35     _alloc_shared,      // Allocate common, outside of TLAB
 36     _alloc_shared_gc,   // Allocate common, outside of GCLAB/PLAB
 37     _alloc_tlab,        // Allocate TLAB
 38     _alloc_gclab,       // Allocate GCLAB
 39     _alloc_plab,        // Allocate PLAB
 40     _ALLOC_LIMIT
 41   };
 42 
 43   static const char* alloc_type_to_string(Type type) {
 44     switch (type) {
 45       case _alloc_shared:
 46         return "Shared";
 47       case _alloc_shared_gc:
 48         return "Shared GC";
 49       case _alloc_tlab:
 50         return "TLAB";
 51       case _alloc_gclab:
 52         return "GCLAB";
 53       case _alloc_plab:
 54         return "PLAB";
 55       default:
 56         ShouldNotReachHere();
 57         return "";
 58     }
 59   }
 60 
 61 private:
 62   // When ShenandoahElasticTLAB is enabled, the request cannot be made smaller than _min_size.
 63   size_t _min_size;
 64 
 65   // The size of the request in words.
 66   size_t _requested_size;
 67 
 68   // The allocation may be increased for padding or decreased to fit in the remaining space of a region.
 69   size_t _actual_size;
 70 
 71   // For a humongous object, the _waste is the amount of free memory in the last region.
 72   // For other requests, the _waste will be non-zero if the request enountered one or more regions
 73   // with less memory than _min_size. This waste does not contribute to the used memory for
 74   // the heap, but it does contribute to the allocation rate for heuristics.
 75   size_t _waste;
 76 
 77   // This is the type of the request.
 78   Type _alloc_type;
 79 
 80   // This is the generation which the request is targeting.
 81   ShenandoahAffiliation const _affiliation;
 82 
 83 #ifdef ASSERT
 84   // Check that this is set before being read.
 85   bool _actual_size_set;
 86 #endif
 87 
 88   ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type, ShenandoahAffiliation affiliation) :
 89           _min_size(_min_size), _requested_size(_requested_size),
 90           _actual_size(0), _waste(0), _alloc_type(_alloc_type), _affiliation(affiliation)
 91 #ifdef ASSERT
 92           , _actual_size_set(false)
 93 #endif
 94   {}
 95 
 96 public:
 97   static inline ShenandoahAllocRequest for_tlab(size_t min_size, size_t requested_size) {
 98     return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab, ShenandoahAffiliation::YOUNG_GENERATION);
 99   }
100 
101   static inline ShenandoahAllocRequest for_gclab(size_t min_size, size_t requested_size) {
102     return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab, ShenandoahAffiliation::YOUNG_GENERATION);
103   }
104 
105   static inline ShenandoahAllocRequest for_plab(size_t min_size, size_t requested_size) {
106     return ShenandoahAllocRequest(min_size, requested_size, _alloc_plab, ShenandoahAffiliation::OLD_GENERATION);
107   }
108 
109   static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size, ShenandoahAffiliation affiliation) {
110     return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc, affiliation);
111   }
112 
113   static inline ShenandoahAllocRequest for_shared(size_t requested_size) {
114     return ShenandoahAllocRequest(0, requested_size, _alloc_shared, ShenandoahAffiliation::YOUNG_GENERATION);
115   }
116 
117   inline size_t size() const {
118     return _requested_size;
119   }
120 
121   inline Type type() const {
122     return _alloc_type;
123   }
124 
125   inline const char* type_string() const {
126     return alloc_type_to_string(_alloc_type);
127   }
128 
129   inline size_t min_size() const {
130     assert (is_lab_alloc(), "Only access for LAB allocs");
131     return _min_size;
132   }
133 
134   inline size_t actual_size() const {
135     assert (_actual_size_set, "Should be set");
136     return _actual_size;
137   }
138 
139   inline void set_actual_size(size_t v) {
140 #ifdef ASSERT
141     assert (!_actual_size_set, "Should not be set");
142     _actual_size_set = true;
143 #endif
144     _actual_size = v;
145   }
146 
147   inline size_t waste() const {
148     return _waste;
149   }
150 
151   inline void set_waste(size_t v) {
152     _waste = v;
153   }
154 
155   inline bool is_mutator_alloc() const {
156     switch (_alloc_type) {
157       case _alloc_tlab:
158       case _alloc_shared:
159         return true;
160       case _alloc_gclab:
161       case _alloc_plab:
162       case _alloc_shared_gc:
163         return false;
164       default:
165         ShouldNotReachHere();
166         return false;
167     }
168   }
169 
170   inline bool is_gc_alloc() const {
171     switch (_alloc_type) {
172       case _alloc_tlab:
173       case _alloc_shared:
174         return false;
175       case _alloc_gclab:
176       case _alloc_plab:
177       case _alloc_shared_gc:
178         return true;
179       default:
180         ShouldNotReachHere();
181         return false;
182     }
183   }
184 
185   inline bool is_lab_alloc() const {
186     switch (_alloc_type) {
187       case _alloc_tlab:
188       case _alloc_gclab:
189       case _alloc_plab:
190         return true;
191       case _alloc_shared:
192       case _alloc_shared_gc:
193         return false;
194       default:
195         ShouldNotReachHere();
196         return false;
197     }
198   }
199 
200   bool is_old() const {
201     return _affiliation == OLD_GENERATION;
202   }
203 
204   bool is_young() const {
205     return _affiliation == YOUNG_GENERATION;
206   }
207 
208   ShenandoahAffiliation affiliation() const {
209     return _affiliation;
210   }
211 
212   const char* affiliation_name() const {
213     return shenandoah_affiliation_name(_affiliation);
214   }
215 };
216 
217 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
< prev index next >