src/hotspot/share/prims/resolvedMethodTable.cpp
author stefank
Tue, 26 Nov 2019 10:47:46 +0100
changeset 59290 97d13893ec3c
parent 59249 29b0d0b61615
permissions -rw-r--r--
8234748: Clean up atomic and orderAccess includes Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     1
/*
53904
9c3fe09f69bc 8078725: method adjustments can be done just once for all classes involved into redefinition
coleenp
parents: 51567
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     4
 *
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     8
 *
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    13
 * accompanied this code).
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    14
 *
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    18
 *
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    21
 * questions.
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    22
 *
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    23
 */
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    24
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 48615
diff changeset
    26
#include "classfile/javaClasses.hpp"
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    27
#include "gc/shared/oopStorage.inline.hpp"
57828
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents: 55478
diff changeset
    28
#include "gc/shared/oopStorageSet.hpp"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49818
diff changeset
    29
#include "logging/log.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    30
#include "memory/allocation.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 48615
diff changeset
    31
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54680
diff changeset
    32
#include "memory/universe.hpp"
48615
31cd0c16f4d2 8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents: 47216
diff changeset
    33
#include "oops/access.inline.hpp"
57828
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents: 55478
diff changeset
    34
#include "oops/method.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    35
#include "oops/oop.inline.hpp"
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49594
diff changeset
    36
#include "oops/weakHandle.inline.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    37
#include "prims/resolvedMethodTable.hpp"
59290
97d13893ec3c 8234748: Clean up atomic and orderAccess includes
stefank
parents: 59249
diff changeset
    38
#include "runtime/atomic.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    39
#include "runtime/handles.inline.hpp"
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    40
#include "runtime/interfaceSupport.inline.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    41
#include "runtime/mutexLocker.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49593
diff changeset
    42
#include "runtime/safepointVerifiers.hpp"
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    43
#include "runtime/timerTrace.hpp"
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    44
#include "utilities/concurrentHashTable.inline.hpp"
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    45
#include "utilities/concurrentHashTableTasks.inline.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    46
#include "utilities/macros.hpp"
48615
31cd0c16f4d2 8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents: 47216
diff changeset
    47
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    48
// 2^24 is max size
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    49
static const size_t END_SIZE = 24;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    50
// If a chain gets to 32 something might be wrong
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    51
static const size_t GROW_HINT = 32;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    52
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    53
static const size_t ResolvedMethodTableSizeLog = 10;
48615
31cd0c16f4d2 8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents: 47216
diff changeset
    54
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    55
unsigned int method_hash(const Method* method) {
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    56
  unsigned int name_hash = method->name()->identity_hash();
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    57
  unsigned int signature_hash = method->signature()->identity_hash();
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    58
  return name_hash ^ signature_hash;
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    59
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    60
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    61
typedef ConcurrentHashTable<ResolvedMethodTableConfig,
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54786
diff changeset
    62
                            mtClass> ResolvedMethodTableHash;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54786
diff changeset
    63
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    64
class ResolvedMethodTableConfig : public AllStatic {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    65
 private:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    66
 public:
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    67
  typedef WeakHandle<vm_resolved_method_table_data> Value;
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    68
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    69
  static uintx get_hash(Value const& value, bool* is_dead) {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    70
    oop val_oop = value.peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    71
    if (val_oop == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    72
      *is_dead = true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    73
      return 0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    74
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    75
    *is_dead = false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    76
    Method* method = java_lang_invoke_ResolvedMethodName::vmtarget(val_oop);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    77
    return method_hash(method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    78
  }
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    79
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    80
  // We use default allocation/deallocation but counted
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    81
  static void* allocate_node(size_t size, Value const& value) {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    82
    ResolvedMethodTable::item_added();
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    83
    return AllocateHeap(size, mtClass);
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    84
  }
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    85
  static void free_node(void* memory, Value const& value) {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    86
    value.release();
55478
ae2e53e379cb 8214822: Move ConcurrentHashTable VALUE parameter to CONFIG
coleenp
parents: 54896
diff changeset
    87
    FreeHeap(memory);
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    88
    ResolvedMethodTable::item_removed();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    89
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    90
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    91
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54786
diff changeset
    92
static ResolvedMethodTableHash* _local_table           = NULL;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54786
diff changeset
    93
static size_t                   _current_size          = (size_t)1 << ResolvedMethodTableSizeLog;
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    94
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54786
diff changeset
    95
volatile bool            ResolvedMethodTable::_has_work              = false;
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    96
54896
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54786
diff changeset
    97
volatile size_t          _items_count           = 0;
ea619918de95 8223956: Make SymbolTable and StringTable AllStatic
coleenp
parents: 54786
diff changeset
    98
volatile size_t          _uncleaned_items_count = 0;
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    99
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   100
void ResolvedMethodTable::create_table() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   101
  _local_table  = new ResolvedMethodTableHash(ResolvedMethodTableSizeLog, END_SIZE, GROW_HINT);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   102
  log_trace(membername, table)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   103
                               _current_size, ResolvedMethodTableSizeLog);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   104
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   105
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   106
size_t ResolvedMethodTable::table_size() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   107
  return (size_t)1 << _local_table->get_size_log2(Thread::current());
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   108
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   109
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   110
class ResolvedMethodTableLookup : StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   111
 private:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   112
  Thread*       _thread;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   113
  uintx         _hash;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   114
  const Method* _method;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   115
  Handle        _found;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   116
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   117
 public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   118
  ResolvedMethodTableLookup(Thread* thread, uintx hash, const Method* key)
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   119
    : _thread(thread), _hash(hash), _method(key) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   120
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   121
  uintx get_hash() const {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   122
    return _hash;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   123
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   124
  bool equals(WeakHandle<vm_resolved_method_table_data>* value, bool* is_dead) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   125
    oop val_oop = value->peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   126
    if (val_oop == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   127
      // dead oop, mark this hash dead for cleaning
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   128
      *is_dead = true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   129
      return false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   130
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   131
    bool equals = _method == java_lang_invoke_ResolvedMethodName::vmtarget(val_oop);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   132
    if (!equals) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   133
      return false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   134
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   135
    // Need to resolve weak handle and Handleize through possible safepoint.
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   136
    _found = Handle(_thread, value->resolve());
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   137
    return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   138
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   139
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   140
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   141
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   142
class ResolvedMethodGet : public StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   143
  Thread*       _thread;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   144
  const Method* _method;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   145
  Handle        _return;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   146
public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   147
  ResolvedMethodGet(Thread* thread, const Method* method) : _thread(thread), _method(method) {}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   148
  void operator()(WeakHandle<vm_resolved_method_table_data>* val) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   149
    oop result = val->resolve();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   150
    assert(result != NULL, "Result should be reachable");
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   151
    _return = Handle(_thread, result);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   152
    log_get();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   153
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   154
  oop get_res_oop() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   155
    return _return();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   156
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   157
  void log_get() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   158
    LogTarget(Trace, membername, table) log;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   159
    if (log.is_enabled()) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   160
      ResourceMark rm;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   161
      log.print("ResolvedMethod entry found for %s",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   162
                _method->name_and_sig_as_C_string());
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   163
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   164
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   165
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   166
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   167
oop ResolvedMethodTable::find_method(const Method* method) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   168
  Thread* thread = Thread::current();
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   169
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   170
  ResolvedMethodTableLookup lookup(thread, method_hash(method), method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   171
  ResolvedMethodGet rmg(thread, method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   172
  _local_table->get(thread, lookup, rmg);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   173
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   174
  return rmg.get_res_oop();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   175
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   176
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   177
static void log_insert(const Method* method) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   178
  LogTarget(Debug, membername, table) log;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   179
  if (log.is_enabled()) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   180
    ResourceMark rm;
54680
5b168a63cec5 8223064: Minor cleanups in ResolvedMethodTable
stefank
parents: 54623
diff changeset
   181
    log.print("ResolvedMethod entry added for %s",
5b168a63cec5 8223064: Minor cleanups in ResolvedMethodTable
stefank
parents: 54623
diff changeset
   182
              method->name_and_sig_as_C_string());
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   183
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   184
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   185
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   186
oop ResolvedMethodTable::add_method(const Method* method, Handle rmethod_name) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   187
  Thread* thread = Thread::current();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   188
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   189
  ResolvedMethodTableLookup lookup(thread, method_hash(method), method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   190
  ResolvedMethodGet rmg(thread, method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   191
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   192
  while (true) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   193
    if (_local_table->get(thread, lookup, rmg)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   194
      return rmg.get_res_oop();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   195
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   196
    WeakHandle<vm_resolved_method_table_data> wh = WeakHandle<vm_resolved_method_table_data>::create(rmethod_name);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   197
    // The hash table takes ownership of the WeakHandle, even if it's not inserted.
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   198
    if (_local_table->insert(thread, lookup, wh)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   199
      log_insert(method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   200
      return wh.resolve();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   201
    }
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   202
  }
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   203
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   204
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   205
void ResolvedMethodTable::item_added() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   206
  Atomic::inc(&_items_count);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   207
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   208
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   209
void ResolvedMethodTable::item_removed() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   210
  Atomic::dec(&_items_count);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   211
  log_trace(membername, table) ("ResolvedMethod entry removed");
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   212
}
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   213
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   214
double ResolvedMethodTable::get_load_factor() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   215
  return (double)_items_count/_current_size;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   216
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   217
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   218
double ResolvedMethodTable::get_dead_factor() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   219
  return (double)_uncleaned_items_count/_current_size;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   220
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   221
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   222
static const double PREF_AVG_LIST_LEN = 2.0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   223
// If we have as many dead items as 50% of the number of bucket
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   224
static const double CLEAN_DEAD_HIGH_WATER_MARK = 0.5;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   225
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   226
void ResolvedMethodTable::check_concurrent_work() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   227
  if (_has_work) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   228
    return;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   229
  }
54431
ad9fa99fa48e 8221992: Fix old method replacement in ResolvedMethodTable
coleenp
parents: 53924
diff changeset
   230
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   231
  double load_factor = get_load_factor();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   232
  double dead_factor = get_dead_factor();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   233
  // We should clean/resize if we have more dead than alive,
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   234
  // more items than preferred load factor or
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   235
  // more dead items than water mark.
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   236
  if ((dead_factor > load_factor) ||
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   237
      (load_factor > PREF_AVG_LIST_LEN) ||
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   238
      (dead_factor > CLEAN_DEAD_HIGH_WATER_MARK)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   239
    log_debug(membername, table)("Concurrent work triggered, live factor: %g dead factor: %g",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   240
                                 load_factor, dead_factor);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   241
    trigger_concurrent_work();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   242
  }
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   243
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   244
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   245
void ResolvedMethodTable::trigger_concurrent_work() {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54574
diff changeset
   246
  MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   247
  _has_work = true;
51472
eb97d1a319f9 8206423: Use locking for cleaning ResolvedMethodTable
pchilanomate
parents: 49982
diff changeset
   248
  Service_lock->notify_all();
eb97d1a319f9 8206423: Use locking for cleaning ResolvedMethodTable
pchilanomate
parents: 49982
diff changeset
   249
}
eb97d1a319f9 8206423: Use locking for cleaning ResolvedMethodTable
pchilanomate
parents: 49982
diff changeset
   250
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   251
void ResolvedMethodTable::do_concurrent_work(JavaThread* jt) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   252
  _has_work = false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   253
  double load_factor = get_load_factor();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   254
  log_debug(membername, table)("Concurrent work, live factor: %g", load_factor);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   255
  // We prefer growing, since that also removes dead items
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   256
  if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   257
    grow(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   258
  } else {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   259
    clean_dead_entries(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   260
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   261
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   262
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   263
void ResolvedMethodTable::grow(JavaThread* jt) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   264
  ResolvedMethodTableHash::GrowTask gt(_local_table);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   265
  if (!gt.prepare(jt)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   266
    return;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   267
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   268
  log_trace(membername, table)("Started to grow");
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   269
  {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   270
    TraceTime timer("Grow", TRACETIME_LOG(Debug, membername, table, perf));
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   271
    while (gt.do_task(jt)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   272
      gt.pause(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   273
      {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   274
        ThreadBlockInVM tbivm(jt);
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   275
      }
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   276
      gt.cont(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   277
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   278
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   279
  gt.done(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   280
  _current_size = table_size();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   281
  log_info(membername, table)("Grown to size:" SIZE_FORMAT, _current_size);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   282
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   283
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   284
struct ResolvedMethodTableDoDelete : StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   285
  void operator()(WeakHandle<vm_resolved_method_table_data>* val) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   286
    /* do nothing */
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   287
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   288
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   289
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   290
struct ResolvedMethodTableDeleteCheck : StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   291
  long _count;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   292
  long _item;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   293
  ResolvedMethodTableDeleteCheck() : _count(0), _item(0) {}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   294
  bool operator()(WeakHandle<vm_resolved_method_table_data>* val) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   295
    ++_item;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   296
    oop tmp = val->peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   297
    if (tmp == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   298
      ++_count;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   299
      return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   300
    } else {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   301
      return false;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   302
    }
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   303
  }
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   304
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   305
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   306
void ResolvedMethodTable::clean_dead_entries(JavaThread* jt) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   307
  ResolvedMethodTableHash::BulkDeleteTask bdt(_local_table);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   308
  if (!bdt.prepare(jt)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   309
    return;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   310
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   311
  ResolvedMethodTableDeleteCheck stdc;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   312
  ResolvedMethodTableDoDelete stdd;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   313
  {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   314
    TraceTime timer("Clean", TRACETIME_LOG(Debug, membername, table, perf));
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   315
    while(bdt.do_task(jt, stdc, stdd)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   316
      bdt.pause(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   317
      {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   318
        ThreadBlockInVM tbivm(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   319
      }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   320
      bdt.cont(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   321
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   322
    bdt.done(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   323
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   324
  log_info(membername, table)("Cleaned %ld of %ld", stdc._count, stdc._item);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   325
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   326
void ResolvedMethodTable::reset_dead_counter() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   327
  _uncleaned_items_count = 0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   328
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   329
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   330
void ResolvedMethodTable::inc_dead_counter(size_t ndead) {
59249
29b0d0b61615 8234737: Harmonize parameter order in Atomic - add
stefank
parents: 57828
diff changeset
   331
  size_t total = Atomic::add(&_uncleaned_items_count, ndead);
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   332
  log_trace(membername, table)(
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   333
     "Uncleaned items:" SIZE_FORMAT " added: " SIZE_FORMAT " total:" SIZE_FORMAT,
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   334
     _uncleaned_items_count, ndead, total);
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   335
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   336
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   337
// After the parallel walk this method must be called to trigger
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   338
// cleaning. Note it might trigger a resize instead.
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   339
void ResolvedMethodTable::finish_dead_counter() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   340
  check_concurrent_work();
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   341
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   342
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   343
#if INCLUDE_JVMTI
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   344
class AdjustMethodEntries : public StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   345
  bool* _trace_name_printed;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   346
public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   347
  AdjustMethodEntries(bool* trace_name_printed) : _trace_name_printed(trace_name_printed) {};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   348
  bool operator()(WeakHandle<vm_resolved_method_table_data>* entry) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   349
    oop mem_name = entry->peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   350
    if (mem_name == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   351
      // Removed
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   352
      return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   353
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   354
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   355
    Method* old_method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(mem_name);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   356
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   357
    if (old_method->is_old()) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   358
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   359
      Method* new_method = (old_method->is_deleted()) ?
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   360
                            Universe::throw_no_such_method_error() :
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   361
                            old_method->get_new_method();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   362
      java_lang_invoke_ResolvedMethodName::set_vmtarget(mem_name, new_method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   363
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   364
      ResourceMark rm;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   365
      if (!(*_trace_name_printed)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   366
        log_info(redefine, class, update)("adjust: name=%s", old_method->method_holder()->external_name());
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   367
         *_trace_name_printed = true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   368
      }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   369
      log_debug(redefine, class, update, constantpool)
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   370
        ("ResolvedMethod method update: %s(%s)",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   371
         new_method->name()->as_C_string(), new_method->signature()->as_C_string());
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   372
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   373
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   374
    return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   375
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   376
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   377
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   378
// It is called at safepoint only for RedefineClasses
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   379
void ResolvedMethodTable::adjust_method_entries(bool * trace_name_printed) {
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   380
  assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   381
  // For each entry in RMT, change to new method
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   382
  AdjustMethodEntries adjust(trace_name_printed);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   383
  _local_table->do_safepoint_scan(adjust);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   384
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   385
#endif // INCLUDE_JVMTI
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   386
54574
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   387
// Verification
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   388
class VerifyResolvedMethod : StackObj {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   389
 public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   390
  bool operator()(WeakHandle<vm_resolved_method_table_data>* val) {
54574
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   391
    oop obj = val->peek();
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   392
    if (obj != NULL) {
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   393
      Method* method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(obj);
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   394
      guarantee(method->is_method(), "Must be");
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   395
      guarantee(!method->is_old(), "Must be");
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   396
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   397
    return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   398
  };
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   399
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   400
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   401
size_t ResolvedMethodTable::items_count() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   402
  return _items_count;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   403
}
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   404
54574
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   405
void ResolvedMethodTable::verify() {
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   406
  VerifyResolvedMethod vcs;
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   407
  if (!_local_table->try_scan(Thread::current(), vcs)) {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   408
    log_info(membername, table)("verify unavailable at this moment");
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   409
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   410
}