hotspot/src/share/vm/gc/g1/g1CodeCacheRemSet.cpp
author jprovino
Tue, 02 Aug 2016 16:39:33 -0400
changeset 40328 a2851f5f1cf6
parent 35879 9892f53e92c9
child 40905 94ffc131534f
permissions -rw-r--r--
8071770: G1 does not implement millis_since_last_gc which is needed by RMI GC Summary: G1 does not return a correct value for the CollectedHeap::millis_since_last_gc Reviewed-by: jmasa, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     1
/*
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     4
 *
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     8
 *
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    14
 *
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    18
 *
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    21
 * questions.
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    22
 *
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    23
 */
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    24
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    25
#include "precompiled.hpp"
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    26
#include "code/codeCache.hpp"
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    27
#include "code/nmethod.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    28
#include "gc/g1/g1CodeCacheRemSet.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29796
diff changeset
    29
#include "gc/g1/heapRegion.hpp"
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    30
#include "memory/heap.hpp"
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    31
#include "memory/iterator.hpp"
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    32
#include "oops/oop.inline.hpp"
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    33
#include "utilities/hashtable.inline.hpp"
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    34
#include "utilities/stack.inline.hpp"
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    35
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    36
class CodeRootSetTable : public Hashtable<nmethod*, mtGC> {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    37
  friend class G1CodeRootSetTest;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    38
  typedef HashtableEntry<nmethod*, mtGC> Entry;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    39
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    40
  static CodeRootSetTable* volatile _purge_list;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    41
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    42
  CodeRootSetTable* _purge_next;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    43
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    44
  unsigned int compute_hash(nmethod* nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    45
    uintptr_t hash = (uintptr_t)nm;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    46
    return hash ^ (hash >> 7); // code heap blocks are 128byte aligned
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    47
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    48
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
    49
  void remove_entry(Entry* e, Entry* previous);
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    50
  Entry* new_entry(nmethod* nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    51
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    52
 public:
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    53
  CodeRootSetTable(int size) : Hashtable<nmethod*, mtGC>(size, sizeof(Entry)), _purge_next(NULL) {}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    54
  ~CodeRootSetTable();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    55
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    56
  // Needs to be protected locks
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    57
  bool add(nmethod* nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    58
  bool remove(nmethod* nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    59
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    60
  // Can be called without locking
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    61
  bool contains(nmethod* nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    62
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    63
  int entry_size() const { return BasicHashtable<mtGC>::entry_size(); }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    64
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    65
  void copy_to(CodeRootSetTable* new_table);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    66
  void nmethods_do(CodeBlobClosure* blk);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    67
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    68
  template<typename CB>
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
    69
  int remove_if(CB& should_remove);
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    70
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    71
  static void purge_list_append(CodeRootSetTable* tbl);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    72
  static void purge();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    73
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    74
  static size_t static_mem_size() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    75
    return sizeof(_purge_list);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    76
  }
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
    77
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
    78
  size_t mem_size();
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    79
};
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    80
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    81
CodeRootSetTable* volatile CodeRootSetTable::_purge_list = NULL;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    82
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
    83
size_t CodeRootSetTable::mem_size() {
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
    84
  return sizeof(CodeRootSetTable) + (entry_size() * number_of_entries()) + (sizeof(HashtableBucket<mtGC>) * table_size());
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
    85
}
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
    86
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    87
CodeRootSetTable::Entry* CodeRootSetTable::new_entry(nmethod* nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    88
  unsigned int hash = compute_hash(nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    89
  Entry* entry = (Entry*) new_entry_free_list();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    90
  if (entry == NULL) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    91
    entry = (Entry*) NEW_C_HEAP_ARRAY2(char, entry_size(), mtGC, CURRENT_PC);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    92
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    93
  entry->set_next(NULL);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    94
  entry->set_hash(hash);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    95
  entry->set_literal(nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
    96
  return entry;
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    97
}
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
    98
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
    99
void CodeRootSetTable::remove_entry(Entry* e, Entry* previous) {
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   100
  int index = hash_to_index(e->hash());
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   101
  assert((e == bucket(index)) == (previous == NULL), "if e is the first entry then previous should be null");
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   102
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   103
  if (previous == NULL) {
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   104
    set_entry(index, e->next());
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   105
  } else {
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   106
    previous->set_next(e->next());
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   107
  }
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   108
  free_entry(e);
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   109
}
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   110
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   111
CodeRootSetTable::~CodeRootSetTable() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   112
  for (int index = 0; index < table_size(); ++index) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   113
    for (Entry* e = bucket(index); e != NULL; ) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   114
      Entry* to_remove = e;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   115
      // read next before freeing.
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   116
      e = e->next();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   117
      unlink_entry(to_remove);
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26574
diff changeset
   118
      FREE_C_HEAP_ARRAY(char, to_remove);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   119
    }
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   120
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   121
  assert(number_of_entries() == 0, "should have removed all entries");
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   122
  free_buckets();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   123
  for (BasicHashtableEntry<mtGC>* e = new_entry_free_list(); e != NULL; e = new_entry_free_list()) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 26574
diff changeset
   124
    FREE_C_HEAP_ARRAY(char, e);
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   125
  }
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   126
}
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   127
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   128
bool CodeRootSetTable::add(nmethod* nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   129
  if (!contains(nm)) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   130
    Entry* e = new_entry(nm);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   131
    int index = hash_to_index(e->hash());
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   132
    add_entry(index, e);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   133
    return true;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   134
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   135
  return false;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   136
}
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   137
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   138
bool CodeRootSetTable::contains(nmethod* nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   139
  int index = hash_to_index(compute_hash(nm));
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   140
  for (Entry* e = bucket(index); e != NULL; e = e->next()) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   141
    if (e->literal() == nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   142
      return true;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   143
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   144
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   145
  return false;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   146
}
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   147
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   148
bool CodeRootSetTable::remove(nmethod* nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   149
  int index = hash_to_index(compute_hash(nm));
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   150
  Entry* previous = NULL;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   151
  for (Entry* e = bucket(index); e != NULL; previous = e, e = e->next()) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   152
    if (e->literal() == nm) {
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   153
      remove_entry(e, previous);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   154
      return true;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   155
    }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   156
  }
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   157
  return false;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   158
}
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   159
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   160
void CodeRootSetTable::copy_to(CodeRootSetTable* new_table) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   161
  for (int index = 0; index < table_size(); ++index) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   162
    for (Entry* e = bucket(index); e != NULL; e = e->next()) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   163
      new_table->add(e->literal());
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   164
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   165
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   166
  new_table->copy_freelist(this);
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   167
}
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   168
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   169
void CodeRootSetTable::nmethods_do(CodeBlobClosure* blk) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   170
  for (int index = 0; index < table_size(); ++index) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   171
    for (Entry* e = bucket(index); e != NULL; e = e->next()) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   172
      blk->do_code_blob(e->literal());
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   173
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   174
  }
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   175
}
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   176
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   177
template<typename CB>
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   178
int CodeRootSetTable::remove_if(CB& should_remove) {
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   179
  int num_removed = 0;
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   180
  for (int index = 0; index < table_size(); ++index) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   181
    Entry* previous = NULL;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   182
    Entry* e = bucket(index);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   183
    while (e != NULL) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   184
      Entry* next = e->next();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   185
      if (should_remove(e->literal())) {
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   186
        remove_entry(e, previous);
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   187
        ++num_removed;
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   188
      } else {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   189
        previous = e;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   190
      }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   191
      e = next;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   192
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   193
  }
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   194
  return num_removed;
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   195
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   196
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   197
G1CodeRootSet::~G1CodeRootSet() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   198
  delete _table;
24099
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   199
}
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   200
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   201
CodeRootSetTable* G1CodeRootSet::load_acquire_table() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   202
  return (CodeRootSetTable*) OrderAccess::load_ptr_acquire(&_table);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   203
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   204
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   205
void G1CodeRootSet::allocate_small_table() {
33093
5aa0f908f8cd 8131645: [ARM64] crash on Cavium when using G1
ecaspole
parents: 31592
diff changeset
   206
  CodeRootSetTable* temp = new CodeRootSetTable(SmallSize);
5aa0f908f8cd 8131645: [ARM64] crash on Cavium when using G1
ecaspole
parents: 31592
diff changeset
   207
5aa0f908f8cd 8131645: [ARM64] crash on Cavium when using G1
ecaspole
parents: 31592
diff changeset
   208
  OrderAccess::release_store_ptr(&_table, temp);
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   209
}
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   210
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   211
void CodeRootSetTable::purge_list_append(CodeRootSetTable* table) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   212
  for (;;) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   213
    table->_purge_next = _purge_list;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   214
    CodeRootSetTable* old = (CodeRootSetTable*) Atomic::cmpxchg_ptr(table, &_purge_list, table->_purge_next);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   215
    if (old == table->_purge_next) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   216
      break;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   217
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   218
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   219
}
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   220
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   221
void CodeRootSetTable::purge() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   222
  CodeRootSetTable* table = _purge_list;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   223
  _purge_list = NULL;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   224
  while (table != NULL) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   225
    CodeRootSetTable* to_purge = table;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   226
    table = table->_purge_next;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   227
    delete to_purge;
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   228
  }
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   229
}
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   230
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   231
void G1CodeRootSet::move_to_large() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   232
  CodeRootSetTable* temp = new CodeRootSetTable(LargeSize);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   233
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   234
  _table->copy_to(temp);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   235
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   236
  CodeRootSetTable::purge_list_append(_table);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   237
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   238
  OrderAccess::release_store_ptr(&_table, temp);
24099
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   239
}
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   240
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   241
void G1CodeRootSet::purge() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   242
  CodeRootSetTable::purge();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   243
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   244
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   245
size_t G1CodeRootSet::static_mem_size() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   246
  return CodeRootSetTable::static_mem_size();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   247
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   248
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   249
void G1CodeRootSet::add(nmethod* method) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   250
  bool added = false;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   251
  if (is_empty()) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   252
    allocate_small_table();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   253
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   254
  added = _table->add(method);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   255
  if (added) {
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   256
    if (_length == Threshold) {
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   257
      move_to_large();
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   258
    }
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   259
    ++_length;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   260
  }
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   261
  assert(_length == (size_t)_table->number_of_entries(), "sizes should match");
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   262
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   263
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   264
bool G1CodeRootSet::remove(nmethod* method) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   265
  bool removed = false;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   266
  if (_table != NULL) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   267
    removed = _table->remove(method);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   268
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   269
  if (removed) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   270
    _length--;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   271
    if (_length == 0) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   272
      clear();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   273
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   274
  }
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   275
  assert((_length == 0 && _table == NULL) ||
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   276
         (_length == (size_t)_table->number_of_entries()), "sizes should match");
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   277
  return removed;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   278
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   279
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   280
bool G1CodeRootSet::contains(nmethod* method) {
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   281
  CodeRootSetTable* table = load_acquire_table(); // contains() may be called outside of lock, so ensure mem sync.
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   282
  if (table != NULL) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   283
    return table->contains(method);
24099
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   284
  }
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   285
  return false;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   286
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   287
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   288
void G1CodeRootSet::clear() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   289
  delete _table;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   290
  _table = NULL;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   291
  _length = 0;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   292
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   293
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   294
size_t G1CodeRootSet::mem_size() {
35879
9892f53e92c9 8141421: Various test fail with OOME on win x86
drwhite
parents: 33105
diff changeset
   295
  return sizeof(*this) + (_table != NULL ? _table->mem_size() : 0);
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   296
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   297
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   298
void G1CodeRootSet::nmethods_do(CodeBlobClosure* blk) const {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   299
  if (_table != NULL) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   300
    _table->nmethods_do(blk);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   301
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   302
}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   303
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   304
class CleanCallback : public StackObj {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   305
  class PointsIntoHRDetectionClosure : public OopClosure {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   306
    HeapRegion* _hr;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   307
   public:
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   308
    bool _points_into;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   309
    PointsIntoHRDetectionClosure(HeapRegion* hr) : _hr(hr), _points_into(false) {}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   310
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   311
    void do_oop(narrowOop* o) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   312
      do_oop_work(o);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   313
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   314
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   315
    void do_oop(oop* o) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   316
      do_oop_work(o);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   317
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   318
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   319
    template <typename T>
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   320
    void do_oop_work(T* p) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   321
      if (_hr->is_in(oopDesc::load_decode_heap_oop(p))) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   322
        _points_into = true;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   323
      }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   324
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   325
  };
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   326
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   327
  PointsIntoHRDetectionClosure _detector;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   328
  CodeBlobToOopClosure _blobs;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   329
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   330
 public:
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   331
  CleanCallback(HeapRegion* hr) : _detector(hr), _blobs(&_detector, !CodeBlobToOopClosure::FixRelocations) {}
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   332
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   333
  bool operator() (nmethod* nm) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   334
    _detector._points_into = false;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   335
    _blobs.do_code_blob(nm);
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   336
    return !_detector._points_into;
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   337
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   338
};
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   339
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   340
void G1CodeRootSet::clean(HeapRegion* owner) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   341
  CleanCallback should_clean(owner);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   342
  if (_table != NULL) {
26574
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   343
    int removed = _table->remove_if(should_clean);
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   344
    assert((size_t)removed <= _length, "impossible");
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   345
    _length -= removed;
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   346
  }
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   347
  if (_length == 0) {
59219d1be209 8057722: G1: Code root hashtable updated incorrectly when evacuation failed
mgerdin
parents: 26422
diff changeset
   348
    clear();
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   349
  }
24099
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   350
}
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   351
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   352
#ifndef PRODUCT
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   353
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   354
class G1CodeRootSetTest {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   355
 public:
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   356
  static void test() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   357
    {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   358
      G1CodeRootSet set1;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   359
      assert(set1.is_empty(), "Code root set must be initially empty but is not.");
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   360
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   361
      assert(G1CodeRootSet::static_mem_size() == sizeof(void*),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   362
             "The code root set's static memory usage is incorrect, " SIZE_FORMAT " bytes", G1CodeRootSet::static_mem_size());
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   363
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   364
      set1.add((nmethod*)1);
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   365
      assert(set1.length() == 1, "Added exactly one element, but set contains "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   366
             SIZE_FORMAT " elements", set1.length());
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   367
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   368
      const size_t num_to_add = (size_t)G1CodeRootSet::Threshold + 1;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   369
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   370
      for (size_t i = 1; i <= num_to_add; i++) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   371
        set1.add((nmethod*)1);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   372
      }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   373
      assert(set1.length() == 1,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   374
             "Duplicate detection should not have increased the set size but "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   375
             "is " SIZE_FORMAT, set1.length());
23451
ed2b8bb28fed 8035406: Improve data structure for Code Cache remembered sets
tschatzl
parents:
diff changeset
   376
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   377
      for (size_t i = 2; i <= num_to_add; i++) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   378
        set1.add((nmethod*)(uintptr_t)(i));
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   379
      }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   380
      assert(set1.length() == num_to_add,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   381
             "After adding in total " SIZE_FORMAT " distinct code roots, they "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   382
             "need to be in the set, but there are only " SIZE_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   383
             num_to_add, set1.length());
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   384
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   385
      assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable");
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   386
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   387
      size_t num_popped = 0;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   388
      for (size_t i = 1; i <= num_to_add; i++) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   389
        bool removed = set1.remove((nmethod*)i);
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   390
        if (removed) {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   391
          num_popped += 1;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   392
        } else {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   393
          break;
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   394
        }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   395
      }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   396
      assert(num_popped == num_to_add,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   397
             "Managed to pop " SIZE_FORMAT " code roots, but only " SIZE_FORMAT " "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33093
diff changeset
   398
             "were added", num_popped, num_to_add);
26422
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   399
      assert(CodeRootSetTable::_purge_list != NULL, "should have grown to large hashtable");
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   400
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   401
      G1CodeRootSet::purge();
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   402
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   403
      assert(CodeRootSetTable::_purge_list == NULL, "should have purged old small tables");
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   404
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   405
    }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   406
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   407
  }
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   408
};
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   409
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   410
void TestCodeCacheRemSet_test() {
4ee5901e205e 8048268: G1 Code Root Migration performs poorly
mgerdin
parents: 25500
diff changeset
   411
  G1CodeRootSetTest::test();
24099
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   412
}
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   413
9c132a88935d 8038930: G1CodeRootSet::test fails with assert(_num_chunks_handed_out == 0) failed: No elements must have been handed out yet
tschatzl
parents: 23451
diff changeset
   414
#endif