1 /*
2 * Copyright (c) 2004, 2015, 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
25 #ifndef SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
26 #define SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
27
28 #include "gc/shared/collectedHeap.hpp"
29 #include "gc/shared/gcCause.hpp"
30 #include "gc/shared/gcUtil.hpp"
31 #include "logging/log.hpp"
32 #include "memory/allocation.hpp"
33 #include "memory/universe.hpp"
34
35 // This class keeps statistical information and computes the
36 // size of the heap.
37
38 // Forward decls
39 class elapsedTimer;
40 class CollectorPolicy;
41
42 class AdaptiveSizePolicy : public CHeapObj<mtGC> {
43 friend class GCAdaptivePolicyCounters;
44 friend class PSGCAdaptivePolicyCounters;
45 friend class CMSGCAdaptivePolicyCounters;
46 protected:
47
48 enum GCPolicyKind {
49 _gc_adaptive_size_policy,
50 _gc_ps_adaptive_size_policy,
51 _gc_cms_adaptive_size_policy
52 };
53 virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
54
55 enum SizePolicyTrueValues {
56 decrease_old_gen_for_throughput_true = -7,
57 decrease_young_gen_for_througput_true = -6,
58
59 increase_old_gen_for_min_pauses_true = -5,
60 decrease_old_gen_for_min_pauses_true = -4,
325 void set_increment_tenuring_threshold_for_gc_cost(bool v) {
326 _increment_tenuring_threshold_for_gc_cost = v;
327 }
328 bool decrement_tenuring_threshold_for_survivor_limit() const {
329 return _decrement_tenuring_threshold_for_survivor_limit;
330 }
331 void set_decrement_tenuring_threshold_for_survivor_limit(bool v) {
332 _decrement_tenuring_threshold_for_survivor_limit = v;
333 }
334 // Return true if the policy suggested a change.
335 bool tenuring_threshold_change() const;
336
337 static bool _debug_perturbation;
338
339 public:
340 AdaptiveSizePolicy(size_t init_eden_size,
341 size_t init_promo_size,
342 size_t init_survivor_size,
343 double gc_pause_goal_sec,
344 uint gc_cost_ratio);
345
346 // Return number default GC threads to use in the next GC.
347 static uint calc_default_active_workers(uintx total_workers,
348 const uintx min_workers,
349 uintx active_workers,
350 uintx application_workers);
351
352 // Return number of GC threads to use in the next GC.
353 // This is called sparingly so as not to change the
354 // number of GC workers gratuitously.
355 // For ParNew collections
356 // For PS scavenge and ParOld collections
357 // For G1 evacuation pauses (subject to update)
358 // Other collection phases inherit the number of
359 // GC workers from the calls above. For example,
360 // a CMS parallel remark uses the same number of GC
361 // workers as the most recent ParNew collection.
362 static uint calc_active_workers(uintx total_workers,
363 uintx active_workers,
364 uintx application_workers);
|
1 /*
2 * Copyright (c) 2004, 2016, 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
25 #ifndef SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
26 #define SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
27
28 #include "gc/shared/collectedHeap.hpp"
29 #include "gc/shared/gcCause.hpp"
30 #include "gc/shared/gcUtil.hpp"
31 #include "logging/log.hpp"
32 #include "memory/allocation.hpp"
33 #include "memory/universe.hpp"
34 #include "runtime/os.hpp"
35
36 // This class keeps statistical information and computes the
37 // size of the heap.
38
39 // Forward decls
40 class elapsedTimer;
41 class CollectorPolicy;
42 class AbstractWorkGang;
43 class GCTaskManager;
44
45 class AdaptiveSizePolicy : public CHeapObj<mtGC> {
46 friend class GCAdaptivePolicyCounters;
47 friend class PSGCAdaptivePolicyCounters;
48 friend class CMSGCAdaptivePolicyCounters;
49 protected:
50
51 enum GCPolicyKind {
52 _gc_adaptive_size_policy,
53 _gc_ps_adaptive_size_policy,
54 _gc_cms_adaptive_size_policy
55 };
56 virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
57
58 enum SizePolicyTrueValues {
59 decrease_old_gen_for_throughput_true = -7,
60 decrease_young_gen_for_througput_true = -6,
61
62 increase_old_gen_for_min_pauses_true = -5,
63 decrease_old_gen_for_min_pauses_true = -4,
328 void set_increment_tenuring_threshold_for_gc_cost(bool v) {
329 _increment_tenuring_threshold_for_gc_cost = v;
330 }
331 bool decrement_tenuring_threshold_for_survivor_limit() const {
332 return _decrement_tenuring_threshold_for_survivor_limit;
333 }
334 void set_decrement_tenuring_threshold_for_survivor_limit(bool v) {
335 _decrement_tenuring_threshold_for_survivor_limit = v;
336 }
337 // Return true if the policy suggested a change.
338 bool tenuring_threshold_change() const;
339
340 static bool _debug_perturbation;
341
342 public:
343 AdaptiveSizePolicy(size_t init_eden_size,
344 size_t init_promo_size,
345 size_t init_survivor_size,
346 double gc_pause_goal_sec,
347 uint gc_cost_ratio);
348
349 // Returns the number of GC threads to create at JVM initialization.
350 // Note that the creation of additional threads is connected to the
351 // ergonomic decision on how many threads to use for an upcoming task.
352 // If the user has chosen to control the number of GC workers, they
353 // must all be created at initialization (since the implementation will
354 // never try to create more).
355 static uint initial_number_of_workers() {
356 uint initial_workers = ParallelGCThreads;
357 if (UseDynamicNumberOfGCThreads && FLAG_IS_DEFAULT(ParallelGCThreads)) {
358 initial_workers = MIN2(2U, ParallelGCThreads);
359 }
360
361 return initial_workers;
362 }
363
364 // Create additional workers as needed.
365 // dynamic_workers - number of workers being requested for an upcoming
366 // parallel task.
367 // total_workers - total number of workers. This is the maximum
368 // number possible.
369 // created_workers - number of workers already created. This maybe
370 // less than, equal to, or greater than dynamic workers. If greater than
371 // or equal to dynamic_workers, nothing is done.
372 // worker_type - type of thread.
373 // initializing - true if this is called to get the initial number of
374 // GC workers.
375 // If initializing is true, do a vm exit if the workers cannot be created.
376 // The initializing = true case is for JVM start up and failing to
377 // create all the worker at start should considered a problem so exit.
378 // If initializing = false, there are already some number of worker
379 // threads and a failure would not be optimal but should not be fatal.
380 template <class WorkerType>
381 inline static bool add_workers(WorkerType* holder,
382 uint& active_workers,
383 uint total_workers,
384 uint& created_workers,
385 os::ThreadType worker_type,
386 bool initializing);
387
388 // Return number default GC threads to use in the next GC.
389 static uint calc_default_active_workers(uintx total_workers,
390 const uintx min_workers,
391 uintx active_workers,
392 uintx application_workers);
393
394 // Return number of GC threads to use in the next GC.
395 // This is called sparingly so as not to change the
396 // number of GC workers gratuitously.
397 // For ParNew collections
398 // For PS scavenge and ParOld collections
399 // For G1 evacuation pauses (subject to update)
400 // Other collection phases inherit the number of
401 // GC workers from the calls above. For example,
402 // a CMS parallel remark uses the same number of GC
403 // workers as the most recent ParNew collection.
404 static uint calc_active_workers(uintx total_workers,
405 uintx active_workers,
406 uintx application_workers);
|