hotspot/src/share/vm/gc_implementation/g1/g1StringDedupQueue.hpp
author pliden
Tue, 18 Mar 2014 19:07:22 +0100
changeset 23472 35e93890ed88
child 24093 095cc0a63ed9
permissions -rw-r--r--
8029075: String deduplication in G1 Summary: Implementation of JEP 192, http://openjdk.java.net/jeps/192 Reviewed-by: brutisso, tschatzl, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     1
/*
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP
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;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    68
  volatile bool              _empty;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    69
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    70
  // Statistics counter, only used for logging.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    71
  uintx                      _dropped;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    72
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    73
  G1StringDedupQueue();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    74
  ~G1StringDedupQueue();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    75
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    76
  static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl, size_t queue);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    77
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    78
public:
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    79
  static void create();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    80
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    81
  // Blocks and waits for the queue to become non-empty.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    82
  static void wait();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    83
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    84
  // Pushes a deduplication candidate onto a specific GC worker queue.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    85
  static void push(uint worker_id, oop java_string);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    86
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    87
  // Pops a deduplication candidate from any queue, returns NULL if
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    88
  // all queues are empty.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    89
  static oop pop();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    90
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    91
  static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    92
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    93
  static void print_statistics(outputStream* st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    94
  static void verify();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    95
};
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP