1 /*
   2  * Copyright (c) 2014, 2020, 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_GC_G1_G1PARSCANTHREADSTATE_INLINE_HPP
  26 #define SHARE_GC_G1_G1PARSCANTHREADSTATE_INLINE_HPP
  27 
  28 #include "gc/g1/g1CollectedHeap.inline.hpp"
  29 #include "gc/g1/g1OopStarChunkedList.inline.hpp"
  30 #include "gc/g1/g1ParScanThreadState.hpp"
  31 #include "gc/g1/g1RemSet.hpp"
  32 #include "oops/access.inline.hpp"
  33 #include "oops/oop.inline.hpp"
  34 
  35 inline void G1ParScanThreadState::push_on_queue(ScannerTask task) {
  36   verify_task(task);
  37   _task_queue->push(task);
  38 }
  39 
  40 bool G1ParScanThreadState::needs_partial_trimming() const {
  41   return !_task_queue->overflow_empty() ||
  42          (_task_queue->size() > _stack_trim_upper_threshold);
  43 }
  44 
  45 void G1ParScanThreadState::trim_queue_partially() {
  46   if (!needs_partial_trimming()) {
  47     return;
  48   }
  49 
  50   const Ticks start = Ticks::now();
  51   trim_queue_to_threshold(_stack_trim_lower_threshold);
  52   assert(_task_queue->overflow_empty(), "invariant");
  53   assert(_task_queue->size() <= _stack_trim_lower_threshold, "invariant");
  54   _trim_ticks += Ticks::now() - start;
  55 }
  56 
  57 void G1ParScanThreadState::trim_queue() {
  58   trim_queue_to_threshold(0);
  59   assert(_task_queue->overflow_empty(), "invariant");
  60   assert(_task_queue->taskqueue_empty(), "invariant");
  61 }
  62 
  63 inline Tickspan G1ParScanThreadState::trim_ticks() const {
  64   return _trim_ticks;
  65 }
  66 
  67 inline void G1ParScanThreadState::reset_trim_ticks() {
  68   _trim_ticks = Tickspan();
  69 }
  70 
  71 template <typename T>
  72 inline void G1ParScanThreadState::remember_root_into_optional_region(T* p) {
  73   oop o = RawAccess<IS_NOT_NULL>::oop_load(p);
  74   uint index = _g1h->heap_region_containing(o)->index_in_opt_cset();
  75   assert(index < _num_optional_regions,
  76          "Trying to access optional region idx %u beyond " SIZE_FORMAT, index, _num_optional_regions);
  77   _oops_into_optional_regions[index].push_root(p);
  78 }
  79 
  80 template <typename T>
  81 inline void G1ParScanThreadState::remember_reference_into_optional_region(T* p) {
  82   oop o = RawAccess<IS_NOT_NULL>::oop_load(p);
  83   uint index = _g1h->heap_region_containing(o)->index_in_opt_cset();
  84   assert(index < _num_optional_regions,
  85          "Trying to access optional region idx %u beyond " SIZE_FORMAT, index, _num_optional_regions);
  86   _oops_into_optional_regions[index].push_oop(p);
  87   verify_task(p);
  88 }
  89 
  90 G1OopStarChunkedList* G1ParScanThreadState::oops_into_optional_region(const HeapRegion* hr) {
  91   assert(hr->index_in_opt_cset() < _num_optional_regions,
  92          "Trying to access optional region idx %u beyond " SIZE_FORMAT " " HR_FORMAT,
  93          hr->index_in_opt_cset(), _num_optional_regions, HR_FORMAT_PARAMS(hr));
  94   return &_oops_into_optional_regions[hr->index_in_opt_cset()];
  95 }
  96 
  97 #endif // SHARE_GC_G1_G1PARSCANTHREADSTATE_INLINE_HPP