hotspot/src/share/vm/gc/g1/g1StringDedupQueue.hpp
author tschatzl
Wed, 25 Nov 2015 14:43:29 +0100
changeset 34300 6075c1e0e913
parent 30764 fec48bf5a827
child 35061 be6025ebffea
permissions -rw-r--r--
8136679: JFR event for adaptive IHOP Reviewed-by: tbenson, mgerdin, sangheki, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24093
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     4
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     8
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    13
 * accompanied this code).
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    14
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    18
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    21
 * questions.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    22
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    23
 */
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24093
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24093
diff changeset
    26
#define SHARE_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    27
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    28
#include "memory/allocation.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    29
#include "oops/oop.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    30
#include "utilities/stack.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    31
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    32
class G1StringDedupUnlinkOrOopsDoClosure;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    33
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    34
//
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    35
// The deduplication queue acts as the communication channel between the stop-the-world
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    36
// mark/evacuation phase and the concurrent deduplication phase. Deduplication candidates
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    37
// found during mark/evacuation are placed on this queue for later processing in the
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    38
// deduplication thread. A queue entry is an oop pointing to a String object (as opposed
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    39
// to entries in the deduplication hashtable which points to character arrays).
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    40
//
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    41
// While users of the queue treat it as a single queue, it is implemented as a set of
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    42
// queues, one queue per GC worker thread, to allow lock-free and cache-friendly enqueue
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    43
// operations by the GC workers.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    44
//
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    45
// The oops in the queue are treated as weak pointers, meaning the objects they point to
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    46
// can become unreachable and pruned (cleared) before being popped by the deduplication
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    47
// thread.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    48
//
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    49
// Pushing to the queue is thread safe (this relies on each thread using a unique worker
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    50
// id), but only allowed during a safepoint. Popping from the queue is NOT thread safe
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    51
// and can only be done by the deduplication thread outside a safepoint.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    52
//
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    53
// The StringDedupQueue_lock is only used for blocking and waking up the deduplication
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    54
// thread in case the queue is empty or becomes non-empty, respectively. This lock does
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    55
// not otherwise protect the queue content.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    56
//
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    57
class G1StringDedupQueue : public CHeapObj<mtGC> {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    58
private:
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    59
  typedef Stack<oop, mtGC> G1StringDedupWorkerQueue;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    60
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    61
  static G1StringDedupQueue* _queue;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    62
  static const size_t        _max_size;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    63
  static const size_t        _max_cache_size;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    64
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    65
  G1StringDedupWorkerQueue*  _queues;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    66
  size_t                     _nqueues;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    67
  size_t                     _cursor;
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    68
  bool                       _cancel;
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    69
  volatile bool              _empty;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    70
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    71
  // Statistics counter, only used for logging.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    72
  uintx                      _dropped;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    73
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    74
  G1StringDedupQueue();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    75
  ~G1StringDedupQueue();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    76
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    77
  static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl, size_t queue);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    78
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    79
public:
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    80
  static void create();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    81
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    82
  // Blocks and waits for the queue to become non-empty.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    83
  static void wait();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    84
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    85
  // Wakes up any thread blocked waiting for the queue to become non-empty.
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    86
  static void cancel_wait();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    87
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    88
  // Pushes a deduplication candidate onto a specific GC worker queue.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    89
  static void push(uint worker_id, oop java_string);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    90
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    91
  // Pops a deduplication candidate from any queue, returns NULL if
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    92
  // all queues are empty.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    93
  static oop pop();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    94
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    95
  static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
  static void print_statistics(outputStream* st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    98
  static void verify();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    99
};
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   100
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24093
diff changeset
   101
#endif // SHARE_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP