hotspot/src/share/vm/gc/g1/g1StringDedupQueue.cpp
author tschatzl
Wed, 25 Nov 2015 14:43:29 +0100
changeset 34300 6075c1e0e913
parent 31592 43f48e165466
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
/*
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 25351
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
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    25
#include "precompiled.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 25351
diff changeset
    26
#include "classfile/javaClasses.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    27
#include "gc/g1/g1CollectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    28
#include "gc/g1/g1StringDedup.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    29
#include "gc/g1/g1StringDedupQueue.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    30
#include "gc/shared/gcLocker.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 25351
diff changeset
    31
#include "oops/oop.inline.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24093
diff changeset
    32
#include "runtime/atomic.inline.hpp"
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    33
#include "runtime/mutexLocker.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    34
#include "utilities/stack.inline.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    35
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    36
G1StringDedupQueue* G1StringDedupQueue::_queue = NULL;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    37
const size_t        G1StringDedupQueue::_max_size = 1000000; // Max number of elements per queue
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    38
const size_t        G1StringDedupQueue::_max_cache_size = 0; // Max cache size per queue
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    39
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    40
G1StringDedupQueue::G1StringDedupQueue() :
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    41
  _cursor(0),
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    42
  _cancel(false),
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    43
  _empty(true),
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    44
  _dropped(0) {
30876
44a71334fd94 8080876: Replace unnecessary MAX2(ParallelGCThreads, 1) calls with ParallelGCThreads
stefank
parents: 30764
diff changeset
    45
  _nqueues = ParallelGCThreads;
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    46
  _queues = NEW_C_HEAP_ARRAY(G1StringDedupWorkerQueue, _nqueues, mtGC);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    47
  for (size_t i = 0; i < _nqueues; i++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    48
    new (_queues + i) G1StringDedupWorkerQueue(G1StringDedupWorkerQueue::default_segment_size(), _max_cache_size, _max_size);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    49
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    50
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    51
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    52
G1StringDedupQueue::~G1StringDedupQueue() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    53
  ShouldNotReachHere();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    54
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    55
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    56
void G1StringDedupQueue::create() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    57
  assert(_queue == NULL, "One string deduplication queue allowed");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    58
  _queue = new G1StringDedupQueue();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    59
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    60
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    61
void G1StringDedupQueue::wait() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    62
  MonitorLockerEx ml(StringDedupQueue_lock, Mutex::_no_safepoint_check_flag);
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    63
  while (_queue->_empty && !_queue->_cancel) {
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    64
    ml.wait(Mutex::_no_safepoint_check_flag);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    65
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    66
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    67
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    68
void G1StringDedupQueue::cancel_wait() {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    69
  MonitorLockerEx ml(StringDedupQueue_lock, Mutex::_no_safepoint_check_flag);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    70
  _queue->_cancel = true;
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    71
  ml.notify();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    72
}
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    73
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    74
void G1StringDedupQueue::push(uint worker_id, oop java_string) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    75
  assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    76
  assert(worker_id < _queue->_nqueues, "Invalid queue");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    77
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    78
  // Push and notify waiter
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    79
  G1StringDedupWorkerQueue& worker_queue = _queue->_queues[worker_id];
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    80
  if (!worker_queue.is_full()) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    81
    worker_queue.push(java_string);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    82
    if (_queue->_empty) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    83
      MonitorLockerEx ml(StringDedupQueue_lock, Mutex::_no_safepoint_check_flag);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    84
      if (_queue->_empty) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    85
        // Mark non-empty and notify waiter
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    86
        _queue->_empty = false;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    87
        ml.notify();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    88
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    89
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    90
  } else {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    91
    // Queue is full, drop the string and update the statistics
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    92
    Atomic::inc_ptr(&_queue->_dropped);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    93
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    94
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    95
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
oop G1StringDedupQueue::pop() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
  assert(!SafepointSynchronize::is_at_safepoint(), "Must not be at safepoint");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    98
  No_Safepoint_Verifier nsv;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    99
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   100
  // Try all queues before giving up
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   101
  for (size_t tries = 0; tries < _queue->_nqueues; tries++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   102
    // The cursor indicates where we left of last time
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   103
    G1StringDedupWorkerQueue* queue = &_queue->_queues[_queue->_cursor];
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   104
    while (!queue->is_empty()) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   105
      oop obj = queue->pop();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   106
      // The oop we pop can be NULL if it was marked
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   107
      // dead. Just ignore those and pop the next oop.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   108
      if (obj != NULL) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   109
        return obj;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   110
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   111
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   112
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   113
    // Try next queue
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   114
    _queue->_cursor = (_queue->_cursor + 1) % _queue->_nqueues;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   115
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   116
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   117
  // Mark empty
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   118
  _queue->_empty = true;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   119
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   120
  return NULL;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   121
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   122
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   123
void G1StringDedupQueue::unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   124
  // A worker thread first claims a queue, which ensures exclusive
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   125
  // access to that queue, then continues to process it.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   126
  for (;;) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   127
    // Grab next queue to scan
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   128
    size_t queue = cl->claim_queue();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   129
    if (queue >= _queue->_nqueues) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   130
      // End of queues
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   131
      break;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   132
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   133
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   134
    // Scan the queue
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   135
    unlink_or_oops_do(cl, queue);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   136
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   137
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   138
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   139
void G1StringDedupQueue::unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl, size_t queue) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   140
  assert(queue < _queue->_nqueues, "Invalid queue");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   141
  StackIterator<oop, mtGC> iter(_queue->_queues[queue]);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   142
  while (!iter.is_empty()) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   143
    oop* p = iter.next_addr();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   144
    if (*p != NULL) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   145
      if (cl->is_alive(*p)) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   146
        cl->keep_alive(p);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   147
      } else {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   148
        // Clear dead reference
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   149
        *p = NULL;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   150
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   151
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   152
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   153
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   154
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   155
void G1StringDedupQueue::print_statistics(outputStream* st) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   156
  st->print_cr(
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   157
    "   [Queue]\n"
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30876
diff changeset
   158
    "      [Dropped: " UINTX_FORMAT "]", _queue->_dropped);
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   159
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   160
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   161
void G1StringDedupQueue::verify() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   162
  for (size_t i = 0; i < _queue->_nqueues; i++) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   163
    StackIterator<oop, mtGC> iter(_queue->_queues[i]);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   164
    while (!iter.is_empty()) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   165
      oop obj = iter.next();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   166
      if (obj != NULL) {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29081
diff changeset
   167
        guarantee(G1CollectedHeap::heap()->is_in_reserved(obj), "Object must be on the heap");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   168
        guarantee(!obj->is_forwarded(), "Object must not be forwarded");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   169
        guarantee(java_lang_String::is_instance(obj), "Object must be a String");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   170
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   171
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   172
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   173
}