src/hotspot/share/utilities/concurrentHashTableTasks.inline.hpp
author rkennke
Wed, 03 Oct 2018 15:22:16 +0200
changeset 52070 e4d72440d60e
parent 51334 cc2c79d22508
child 53244 9807daeb47c4
permissions -rw-r--r--
8211279: Verify missing object equals barriers Reviewed-by: pliden, shade, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     1
/*
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     4
 *
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     8
 *
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    13
 * accompanied this code).
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    14
 *
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    18
 *
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    21
 * questions.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    22
 *
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    23
 */
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    24
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    25
#ifndef SHARE_UTILITIES_CONCURRENT_HASH_TABLE_TASKS_INLINE_HPP
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    26
#define SHARE_UTILITIES_CONCURRENT_HASH_TABLE_TASKS_INLINE_HPP
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    27
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50158
diff changeset
    28
#include "utilities/globalDefinitions.hpp"
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    29
#include "utilities/concurrentHashTable.inline.hpp"
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    30
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    31
// This inline file contains BulkDeleteTask and GrowTasks which are both bucket
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    32
// operations, which they are serialized with each other.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    33
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    34
// Base class for pause and/or parallel bulk operations.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    35
template <typename VALUE, typename CONFIG, MEMFLAGS F>
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    36
class ConcurrentHashTable<VALUE, CONFIG, F>::BucketsOperation {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    37
 protected:
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    38
  ConcurrentHashTable<VALUE, CONFIG, F>* _cht;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    39
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    40
  // Default size of _task_size_log2
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    41
  static const size_t DEFAULT_TASK_SIZE_LOG2 = 12;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    42
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    43
  // The table is split into ranges, every increment is one range.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    44
  volatile size_t _next_to_claim;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    45
  size_t _task_size_log2; // Number of buckets.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    46
  size_t _stop_task;      // Last task
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    47
  size_t _size_log2;      // Table size.
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
    48
  bool   _is_mt;
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    49
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
    50
  BucketsOperation(ConcurrentHashTable<VALUE, CONFIG, F>* cht, bool is_mt = false)
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50815
diff changeset
    51
    : _cht(cht), _next_to_claim(0), _task_size_log2(DEFAULT_TASK_SIZE_LOG2),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50815
diff changeset
    52
    _stop_task(0), _size_log2(0), _is_mt(is_mt) {}
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    53
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    54
  // Returns true if you succeeded to claim the range start -> (stop-1).
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    55
  bool claim(size_t* start, size_t* stop) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    56
    size_t claimed = Atomic::add((size_t)1, &_next_to_claim) - 1;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    57
    if (claimed >= _stop_task) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    58
      return false;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    59
    }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    60
    *start = claimed * (((size_t)1) << _task_size_log2);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    61
    *stop  = ((*start) + (((size_t)1) << _task_size_log2));
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    62
    return true;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    63
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    64
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    65
  // Calculate starting values.
50815
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
    66
  void setup(Thread* thread) {
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
    67
    thread_owns_resize_lock(thread);
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    68
    _size_log2 = _cht->_table->_log2_size;
50445
bd6b78feb6a3 8195097: Make it possible to process StringTable outside safepoint
rehn
parents: 50158
diff changeset
    69
    _task_size_log2 = MIN2(_task_size_log2, _size_log2);
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    70
    size_t tmp = _size_log2 > _task_size_log2 ?
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    71
                 _size_log2 - _task_size_log2 : 0;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    72
    _stop_task = (((size_t)1) << tmp);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    73
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    74
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    75
  // Returns false if all ranges are claimed.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    76
  bool have_more_work() {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    77
    return OrderAccess::load_acquire(&_next_to_claim) >= _stop_task;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    78
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    79
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    80
  void thread_owns_resize_lock(Thread* thread) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    81
    assert(BucketsOperation::_cht->_resize_lock_owner == thread,
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    82
           "Should be locked by me");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    83
    assert(BucketsOperation::_cht->_resize_lock->owned_by_self(),
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    84
           "Operations lock not held");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    85
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    86
  void thread_owns_only_state_lock(Thread* thread) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    87
    assert(BucketsOperation::_cht->_resize_lock_owner == thread,
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    88
           "Should be locked by me");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    89
    assert(!BucketsOperation::_cht->_resize_lock->owned_by_self(),
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    90
           "Operations lock held");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    91
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    92
  void thread_do_not_own_resize_lock(Thread* thread) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    93
    assert(!BucketsOperation::_cht->_resize_lock->owned_by_self(),
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    94
           "Operations lock held");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    95
    assert(BucketsOperation::_cht->_resize_lock_owner != thread,
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    96
           "Should not be locked by me");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
    97
  }
50815
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
    98
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
    99
public:
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   100
  // Pauses for safepoint
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   101
  void pause(Thread* thread) {
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   102
    // This leaves internal state locked.
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   103
    this->thread_owns_resize_lock(thread);
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   104
    BucketsOperation::_cht->_resize_lock->unlock();
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   105
    this->thread_owns_only_state_lock(thread);
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   106
  }
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   107
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   108
  // Continues after safepoint.
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   109
  void cont(Thread* thread) {
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   110
    this->thread_owns_only_state_lock(thread);
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   111
    // If someone slips in here directly after safepoint.
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   112
    while (!BucketsOperation::_cht->_resize_lock->try_lock())
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   113
      { /* for ever */ };
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   114
    this->thread_owns_resize_lock(thread);
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   115
  }
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   116
};
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   117
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   118
// For doing pausable/parallel bulk delete.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   119
template <typename VALUE, typename CONFIG, MEMFLAGS F>
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   120
class ConcurrentHashTable<VALUE, CONFIG, F>::BulkDeleteTask :
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   121
  public BucketsOperation
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   122
{
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   123
 public:
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
   124
  BulkDeleteTask(ConcurrentHashTable<VALUE, CONFIG, F>* cht, bool is_mt = false)
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
   125
    : BucketsOperation(cht, is_mt) {
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   126
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   127
  // Before start prepare must be called.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   128
  bool prepare(Thread* thread) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   129
    bool lock = BucketsOperation::_cht->try_resize_lock(thread);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   130
    if (!lock) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   131
      return false;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   132
    }
50815
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   133
    this->setup(thread);
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   134
    return true;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   135
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   136
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   137
  // Does one range destroying all matching EVALUATE_FUNC and
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   138
  // DELETE_FUNC is called be destruction. Returns true if there is more work.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   139
  template <typename EVALUATE_FUNC, typename DELETE_FUNC>
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
   140
  bool do_task(Thread* thread, EVALUATE_FUNC& eval_f, DELETE_FUNC& del_f) {
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   141
    size_t start, stop;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   142
    assert(BucketsOperation::_cht->_resize_lock_owner != NULL,
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   143
           "Should be locked");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   144
    if (!this->claim(&start, &stop)) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   145
      return false;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   146
    }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   147
    BucketsOperation::_cht->do_bulk_delete_locked_for(thread, start, stop,
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
   148
                                                      eval_f, del_f,
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
   149
                                                      BucketsOperation::_is_mt);
50815
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   150
    assert(BucketsOperation::_cht->_resize_lock_owner != NULL,
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   151
           "Should be locked");
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   152
    return true;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   153
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   154
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   155
  // Must be called after ranges are done.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   156
  void done(Thread* thread) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   157
    this->thread_owns_resize_lock(thread);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   158
    BucketsOperation::_cht->unlock_resize_lock(thread);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   159
    this->thread_do_not_own_resize_lock(thread);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   160
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   161
};
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   162
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   163
template <typename VALUE, typename CONFIG, MEMFLAGS F>
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   164
class ConcurrentHashTable<VALUE, CONFIG, F>::GrowTask :
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   165
  public BucketsOperation
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   166
{
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   167
 public:
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   168
  GrowTask(ConcurrentHashTable<VALUE, CONFIG, F>* cht) : BucketsOperation(cht) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   169
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   170
  // Before start prepare must be called.
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   171
  bool prepare(Thread* thread) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   172
    if (!BucketsOperation::_cht->internal_grow_prolog(
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   173
          thread, BucketsOperation::_cht->_log2_size_limit)) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   174
      return false;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   175
    }
50815
54a285a5c6cb 8205583: Crash in ConcurrentHashTable do_bulk_delete_locked_for
rehn
parents: 50608
diff changeset
   176
    this->setup(thread);
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   177
    return true;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   178
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   179
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   180
  // Re-sizes a portion of the table. Returns true if there is more work.
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
   181
  bool do_task(Thread* thread) {
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   182
    size_t start, stop;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   183
    assert(BucketsOperation::_cht->_resize_lock_owner != NULL,
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   184
           "Should be locked");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   185
    if (!this->claim(&start, &stop)) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   186
      return false;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   187
    }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   188
    BucketsOperation::_cht->internal_grow_range(thread, start, stop);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   189
    assert(BucketsOperation::_cht->_resize_lock_owner != NULL,
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   190
           "Should be locked");
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   191
    return true;
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   192
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   193
50608
1609a43e77ae 8204857: ConcurrentHashTable: Fix parallel processing
rehn
parents: 50445
diff changeset
   194
  // Must be called after do_task returns false.
50158
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   195
  void done(Thread* thread) {
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   196
    this->thread_owns_resize_lock(thread);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   197
    BucketsOperation::_cht->internal_grow_epilog(thread);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   198
    this->thread_do_not_own_resize_lock(thread);
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   199
  }
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   200
};
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   201
8e4fcfb4cfe4 8195098: Low latency hashtable for read-mostly scenarios
rehn
parents:
diff changeset
   202
#endif // include guard