1 /*
2 * Copyright (c) 2001, 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
25 #include "precompiled.hpp"
26 #include "gc/g1/g1ConcurrentRefine.hpp"
27 #include "gc/g1/g1ConcurrentRefineThread.hpp"
28 #include "logging/log.hpp"
29 #include "memory/allocation.inline.hpp"
30 #include "runtime/java.hpp"
31 #include "runtime/thread.hpp"
32 #include "utilities/debug.hpp"
33 #include "utilities/globalDefinitions.hpp"
34 #include "utilities/pair.hpp"
35 #include <math.h>
36
37 G1ConcurrentRefineThread* G1ConcurrentRefineThreadControl::create_refinement_thread(uint worker_id, bool initializing) {
38 G1ConcurrentRefineThread* result = NULL;
39 if (initializing || !InjectGCWorkerCreationFailure) {
40 result = new G1ConcurrentRefineThread(_cr, worker_id);
41 }
42 if (result == NULL || result->osthread() == NULL) {
43 log_warning(gc)("Failed to create refinement thread %u, no more %s",
44 worker_id,
45 result == NULL ? "memory" : "OS threads");
360 goal_ms);
361
362 _green_zone = calc_new_green_zone(_green_zone,
363 update_rs_time,
364 update_rs_processed_buffers,
365 goal_ms);
366 _yellow_zone = calc_new_yellow_zone(_green_zone, _min_yellow_zone_size);
367 _red_zone = calc_new_red_zone(_green_zone, _yellow_zone);
368
369 assert_zone_constraints_gyr(_green_zone, _yellow_zone, _red_zone);
370 LOG_ZONES("Updated Refinement Zones: "
371 "green: " SIZE_FORMAT ", "
372 "yellow: " SIZE_FORMAT ", "
373 "red: " SIZE_FORMAT,
374 _green_zone, _yellow_zone, _red_zone);
375 }
376
377 void G1ConcurrentRefine::adjust(double update_rs_time,
378 size_t update_rs_processed_buffers,
379 double goal_ms) {
380 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
381
382 if (G1UseAdaptiveConcRefinement) {
383 update_zones(update_rs_time, update_rs_processed_buffers, goal_ms);
384
385 // Change the barrier params
386 if (max_num_threads() == 0) {
387 // Disable dcqs notification when there are no threads to notify.
388 dcqs.set_process_completed_threshold(INT_MAX);
389 } else {
390 // Worker 0 is the primary; wakeup is via dcqs notification.
391 STATIC_ASSERT(max_yellow_zone <= INT_MAX);
392 size_t activate = activation_threshold(0);
393 dcqs.set_process_completed_threshold((int)activate);
394 }
395 dcqs.set_max_completed_queue((int)red_zone());
396 }
397
398 size_t curr_queue_size = dcqs.completed_buffers_num();
399 if (curr_queue_size >= yellow_zone()) {
400 dcqs.set_completed_queue_padding(curr_queue_size);
408 Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, worker_id);
409 return activation_level(thresholds);
410 }
411
412 size_t G1ConcurrentRefine::deactivation_threshold(uint worker_id) const {
413 Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, worker_id);
414 return deactivation_level(thresholds);
415 }
416
417 uint G1ConcurrentRefine::worker_id_offset() {
418 return DirtyCardQueueSet::num_par_ids();
419 }
420
421 void G1ConcurrentRefine::maybe_activate_more_threads(uint worker_id, size_t num_cur_buffers) {
422 if (num_cur_buffers > activation_threshold(worker_id + 1)) {
423 _thread_control.maybe_activate_next(worker_id);
424 }
425 }
426
427 bool G1ConcurrentRefine::do_refinement_step(uint worker_id) {
428 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
429
430 size_t curr_buffer_num = dcqs.completed_buffers_num();
431 // If the number of the buffers falls down into the yellow zone,
432 // that means that the transition period after the evacuation pause has ended.
433 // Since the value written to the DCQS is the same for all threads, there is no
434 // need to synchronize.
435 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= yellow_zone()) {
436 dcqs.set_completed_queue_padding(0);
437 }
438
439 maybe_activate_more_threads(worker_id, curr_buffer_num);
440
441 // Process the next buffer, if there are enough left.
442 return dcqs.refine_completed_buffer_concurrently(worker_id + worker_id_offset(),
443 deactivation_threshold(worker_id));
444 }
|
1 /*
2 * Copyright (c) 2001, 2018, 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 #include "precompiled.hpp"
26 #include "gc/g1/g1BarrierSet.hpp"
27 #include "gc/g1/g1ConcurrentRefine.hpp"
28 #include "gc/g1/g1ConcurrentRefineThread.hpp"
29 #include "logging/log.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "runtime/java.hpp"
32 #include "runtime/thread.hpp"
33 #include "utilities/debug.hpp"
34 #include "utilities/globalDefinitions.hpp"
35 #include "utilities/pair.hpp"
36 #include <math.h>
37
38 G1ConcurrentRefineThread* G1ConcurrentRefineThreadControl::create_refinement_thread(uint worker_id, bool initializing) {
39 G1ConcurrentRefineThread* result = NULL;
40 if (initializing || !InjectGCWorkerCreationFailure) {
41 result = new G1ConcurrentRefineThread(_cr, worker_id);
42 }
43 if (result == NULL || result->osthread() == NULL) {
44 log_warning(gc)("Failed to create refinement thread %u, no more %s",
45 worker_id,
46 result == NULL ? "memory" : "OS threads");
361 goal_ms);
362
363 _green_zone = calc_new_green_zone(_green_zone,
364 update_rs_time,
365 update_rs_processed_buffers,
366 goal_ms);
367 _yellow_zone = calc_new_yellow_zone(_green_zone, _min_yellow_zone_size);
368 _red_zone = calc_new_red_zone(_green_zone, _yellow_zone);
369
370 assert_zone_constraints_gyr(_green_zone, _yellow_zone, _red_zone);
371 LOG_ZONES("Updated Refinement Zones: "
372 "green: " SIZE_FORMAT ", "
373 "yellow: " SIZE_FORMAT ", "
374 "red: " SIZE_FORMAT,
375 _green_zone, _yellow_zone, _red_zone);
376 }
377
378 void G1ConcurrentRefine::adjust(double update_rs_time,
379 size_t update_rs_processed_buffers,
380 double goal_ms) {
381 DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
382
383 if (G1UseAdaptiveConcRefinement) {
384 update_zones(update_rs_time, update_rs_processed_buffers, goal_ms);
385
386 // Change the barrier params
387 if (max_num_threads() == 0) {
388 // Disable dcqs notification when there are no threads to notify.
389 dcqs.set_process_completed_threshold(INT_MAX);
390 } else {
391 // Worker 0 is the primary; wakeup is via dcqs notification.
392 STATIC_ASSERT(max_yellow_zone <= INT_MAX);
393 size_t activate = activation_threshold(0);
394 dcqs.set_process_completed_threshold((int)activate);
395 }
396 dcqs.set_max_completed_queue((int)red_zone());
397 }
398
399 size_t curr_queue_size = dcqs.completed_buffers_num();
400 if (curr_queue_size >= yellow_zone()) {
401 dcqs.set_completed_queue_padding(curr_queue_size);
409 Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, worker_id);
410 return activation_level(thresholds);
411 }
412
413 size_t G1ConcurrentRefine::deactivation_threshold(uint worker_id) const {
414 Thresholds thresholds = calc_thresholds(_green_zone, _yellow_zone, worker_id);
415 return deactivation_level(thresholds);
416 }
417
418 uint G1ConcurrentRefine::worker_id_offset() {
419 return DirtyCardQueueSet::num_par_ids();
420 }
421
422 void G1ConcurrentRefine::maybe_activate_more_threads(uint worker_id, size_t num_cur_buffers) {
423 if (num_cur_buffers > activation_threshold(worker_id + 1)) {
424 _thread_control.maybe_activate_next(worker_id);
425 }
426 }
427
428 bool G1ConcurrentRefine::do_refinement_step(uint worker_id) {
429 DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
430
431 size_t curr_buffer_num = dcqs.completed_buffers_num();
432 // If the number of the buffers falls down into the yellow zone,
433 // that means that the transition period after the evacuation pause has ended.
434 // Since the value written to the DCQS is the same for all threads, there is no
435 // need to synchronize.
436 if (dcqs.completed_queue_padding() > 0 && curr_buffer_num <= yellow_zone()) {
437 dcqs.set_completed_queue_padding(0);
438 }
439
440 maybe_activate_more_threads(worker_id, curr_buffer_num);
441
442 // Process the next buffer, if there are enough left.
443 return dcqs.refine_completed_buffer_concurrently(worker_id + worker_id_offset(),
444 deactivation_threshold(worker_id));
445 }
|