1 /*
   2  * Copyright (c) 2013, 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_IMPLEMENTATION_G1_PRESERVEMARKQUEUE_HPP
  26 #define SHARE_VM_GC_IMPLEMENTATION_G1_PRESERVEMARKQUEUE_HPP
  27 
  28 #include "oops/oopsHierarchy.hpp"
  29 
  30 struct G1PreserveMarkQueueEntry {
  31   oop obj;
  32   markOop mark;
  33 };
  34 
  35 class G1PreserveMarkChunk;
  36 
  37 class G1PreserveMarkQueue {
  38   const size_t _initial_chunk_capacity;
  39   const size_t _max_chunk_capacity;
  40   size_t _current_capacity;
  41   G1PreserveMarkChunk* _current_write_chunk;
  42   G1PreserveMarkChunk* _current_read_chunk;
  43 
  44  public:
  45   G1PreserveMarkQueue(size_t initial_chunk_capacity, size_t max_chunk_capacity) :
  46     _initial_chunk_capacity(initial_chunk_capacity), _max_chunk_capacity(max_chunk_capacity),
  47     _current_write_chunk(NULL), _current_read_chunk(NULL) {
  48     assert(_initial_chunk_capacity <= _max_chunk_capacity, "initial must be <= max");
  49   }
  50 
  51   bool has_data();
  52   void append(const oop& obj, const markOop& mark);
  53   G1PreserveMarkQueueEntry remove_first();
  54 
  55   size_t new_chunk_capacity() {
  56     if (_current_write_chunk == NULL) {
  57       _current_capacity = _initial_chunk_capacity;
  58     } else if (_current_capacity == _max_chunk_capacity) {
  59       // do nothing. already at max capacity
  60     } else {
  61       // Grow with 50%, similar to java.util.ArrayList
  62       _current_capacity += _current_capacity >> 1;
  63       _current_capacity = MIN2(_current_capacity, _max_chunk_capacity);
  64     }
  65 
  66     assert(_current_capacity >= _initial_chunk_capacity, "too small capacity");
  67     assert(_current_capacity <= _max_chunk_capacity, "too large capacity");
  68 
  69     return _current_capacity;
  70   }
  71 
  72   NOT_PRODUCT(void verify_empty());
  73 };
  74 
  75 NOT_PRODUCT(void g1PreserveMarkChunkTests());
  76 NOT_PRODUCT(void g1PreserveMarkQueueTests());
  77 
  78 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_PRESERVEMARKQUEUE_HPP