src/hotspot/share/gc/g1/g1FreeIdSet.hpp
author kbarrett
Fri, 25 Jan 2019 00:27:51 -0500
changeset 53482 771b50dd0b08
child 57969 6f0215981777
permissions -rw-r--r--
8216258: Make FreeIdSet semaphore-based Summary: Use semaphore-based blocking and notifying, instead of Mutex. Reviewed-by: tschatzl, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53482
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     1
/*
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     4
 *
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     7
 * published by the Free Software Foundation.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     8
 *
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    13
 * accompanied this code).
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    14
 *
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    18
 *
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    21
 * questions.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    22
 *
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    23
 */
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    24
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    25
#ifndef SHARE_GC_G1_G1FREEIDSET_HPP
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    26
#define SHARE_GC_G1_G1FREEIDSET_HPP
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    27
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    28
#include "memory/allocation.hpp"
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    29
#include "runtime/semaphore.hpp"
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    31
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    32
// Represents a set of small integer ids, from which elements can be
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    33
// temporarily allocated for exclusive use.  The ids are in a
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    34
// contiguous range from 'start' to 'start + size'.  Used to obtain a
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    35
// distinct worker_id value for a mutator thread that doesn't normally
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    36
// have such an id.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    37
class G1FreeIdSet : public CHeapObj<mtGC> {
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    38
  Semaphore _sem;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    39
  uint* _next;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    40
  uint _start;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    41
  uint _size;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    42
  uintx _head_index_mask;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    43
  volatile uintx _head;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    44
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    45
  uint head_index(uintx head) const;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    46
  uintx make_head(uint index, uintx old_head) const;
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    47
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    48
  // Noncopyable.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    49
  G1FreeIdSet(const G1FreeIdSet&);
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    50
  G1FreeIdSet& operator=(const G1FreeIdSet&);
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    51
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    52
public:
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    53
  G1FreeIdSet(uint start, uint size);
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    54
  ~G1FreeIdSet();
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    55
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    56
  // Returns an unclaimed parallel id (waiting for one to be released if
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    57
  // necessary).  Must not safepoint while holding a claimed id.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    58
  uint claim_par_id();
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    59
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    60
  void release_par_id(uint id);
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    61
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    62
  struct TestSupport;           // For unit test access.
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    63
};
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    64
771b50dd0b08 8216258: Make FreeIdSet semaphore-based
kbarrett
parents:
diff changeset
    65
#endif // SHARE_GC_G1_G1FREEIDSET_HPP