src/hotspot/share/prims/resolvedMethodTable.cpp
author stefank
Wed, 17 Apr 2019 07:41:09 +0200
changeset 54574 7b74bbe5085b
parent 54511 fbfcebad8e66
child 54623 1126f0607c70
permissions -rw-r--r--
8222558: Rework ResolvedMethodTable verification Reviewed-by: coleenp
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"
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49818
diff changeset
    28
#include "logging/log.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    29
#include "memory/allocation.hpp"
49593
4dd58ecc9912 8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents: 48615
diff changeset
    30
#include "memory/resourceArea.hpp"
48615
31cd0c16f4d2 8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents: 47216
diff changeset
    31
#include "oops/access.inline.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    32
#include "oops/oop.inline.hpp"
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    33
#include "oops/method.hpp"
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49594
diff changeset
    34
#include "oops/weakHandle.inline.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    35
#include "prims/resolvedMethodTable.hpp"
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    36
#include "runtime/handles.inline.hpp"
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    37
#include "runtime/interfaceSupport.inline.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    38
#include "runtime/mutexLocker.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49593
diff changeset
    39
#include "runtime/safepointVerifiers.hpp"
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    40
#include "runtime/timerTrace.hpp"
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    41
#include "utilities/concurrentHashTable.inline.hpp"
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    42
#include "utilities/concurrentHashTableTasks.inline.hpp"
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    43
#include "utilities/macros.hpp"
48615
31cd0c16f4d2 8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents: 47216
diff changeset
    44
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    45
// 2^24 is max size
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    46
static const size_t END_SIZE = 24;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    47
// If a chain gets to 32 something might be wrong
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    48
static const size_t GROW_HINT = 32;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    49
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    50
static const size_t ResolvedMethodTableSizeLog = 10;
48615
31cd0c16f4d2 8191904: Refactor weak oops in ResolvedMethodTable to use the Access API
eosterlund
parents: 47216
diff changeset
    51
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    52
unsigned int method_hash(const Method* method) {
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    53
  unsigned int name_hash = method->name()->identity_hash();
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    54
  unsigned int signature_hash = method->signature()->identity_hash();
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    55
  return name_hash ^ signature_hash;
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    56
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    57
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    58
class ResolvedMethodTableConfig : public ResolvedMethodTableHash::BaseConfig {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    59
 private:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    60
 public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    61
  static uintx get_hash(WeakHandle<vm_resolved_method_table_data> const& value,
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    62
                        bool* is_dead) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    63
    EXCEPTION_MARK;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    64
    oop val_oop = value.peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    65
    if (val_oop == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    66
      *is_dead = true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    67
      return 0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    68
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    69
    *is_dead = false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    70
    Method* method = java_lang_invoke_ResolvedMethodName::vmtarget(val_oop);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    71
    return method_hash(method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    72
  }
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
    73
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    74
  // We use default allocation/deallocation but counted
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    75
  static void* allocate_node(size_t size, WeakHandle<vm_resolved_method_table_data> const& value) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    76
    ResolvedMethodTable::item_added();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    77
    return ResolvedMethodTableHash::BaseConfig::allocate_node(size, value);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    78
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    79
  static void free_node(void* memory, WeakHandle<vm_resolved_method_table_data> const& value) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    80
    value.release();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    81
    ResolvedMethodTableHash::BaseConfig::free_node(memory, value);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    82
    ResolvedMethodTable::item_removed();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    83
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    84
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    85
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    86
ResolvedMethodTableHash* ResolvedMethodTable::_local_table           = NULL;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    87
size_t                   ResolvedMethodTable::_current_size          = (size_t)1 << ResolvedMethodTableSizeLog;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    88
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    89
OopStorage*              ResolvedMethodTable::_weak_handles          = NULL;
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
volatile bool            ResolvedMethodTable::_has_work              = false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    92
volatile size_t          ResolvedMethodTable::_items_count           = 0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    93
volatile size_t          ResolvedMethodTable::_uncleaned_items_count = 0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    94
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    95
void ResolvedMethodTable::create_table() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    96
  _local_table  = new ResolvedMethodTableHash(ResolvedMethodTableSizeLog, END_SIZE, GROW_HINT);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    97
  _weak_handles = new OopStorage("ResolvedMethodTable weak",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    98
                                 ResolvedMethodTableWeakAlloc_lock,
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
    99
                                 ResolvedMethodTableWeakActive_lock);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   100
  log_trace(membername, table)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   101
                               _current_size, ResolvedMethodTableSizeLog);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   102
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   103
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   104
size_t ResolvedMethodTable::table_size() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   105
  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
   106
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   107
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   108
class ResolvedMethodTableLookup : StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   109
 private:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   110
  Thread*       _thread;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   111
  uintx         _hash;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   112
  const Method* _method;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   113
  Handle        _found;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   114
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   115
 public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   116
  ResolvedMethodTableLookup(Thread* thread, uintx hash, const Method* key)
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   117
    : _thread(thread), _hash(hash), _method(key) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   118
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   119
  uintx get_hash() const {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   120
    return _hash;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   121
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   122
  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
   123
    oop val_oop = value->peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   124
    if (val_oop == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   125
      // dead oop, mark this hash dead for cleaning
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   126
      *is_dead = true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   127
      return false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   128
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   129
    bool equals = _method == java_lang_invoke_ResolvedMethodName::vmtarget(val_oop);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   130
    if (!equals) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   131
      return false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   132
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   133
    // Need to resolve weak handle and Handleize through possible safepoint.
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   134
    _found = Handle(_thread, value->resolve());
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   135
    return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   136
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   137
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   138
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   139
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   140
class ResolvedMethodGet : public StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   141
  Thread*       _thread;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   142
  const Method* _method;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   143
  Handle        _return;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   144
public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   145
  ResolvedMethodGet(Thread* thread, const Method* method) : _thread(thread), _method(method) {}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   146
  void operator()(WeakHandle<vm_resolved_method_table_data>* val) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   147
    oop result = val->resolve();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   148
    assert(result != NULL, "Result should be reachable");
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   149
    _return = Handle(_thread, result);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   150
    log_get();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   151
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   152
  oop get_res_oop() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   153
    return _return();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   154
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   155
  void log_get() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   156
    LogTarget(Trace, membername, table) log;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   157
    if (log.is_enabled()) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   158
      ResourceMark rm;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   159
      log.print("ResolvedMethod entry found for %s",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   160
                _method->name_and_sig_as_C_string());
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   161
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   162
  }
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
oop ResolvedMethodTable::find_method(const Method* method) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   166
  Thread* thread = Thread::current();
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   167
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   168
  ResolvedMethodTableLookup lookup(thread, method_hash(method), method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   169
  ResolvedMethodGet rmg(thread, method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   170
  _local_table->get(thread, lookup, rmg);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   171
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   172
  return rmg.get_res_oop();
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
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   175
static void log_insert(const Method* method) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   176
  LogTarget(Debug, membername, table) log;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   177
  if (log.is_enabled()) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   178
    ResourceMark rm;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   179
    log_debug(membername, table) ("ResolvedMethod entry added for %s",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   180
                                  method->name_and_sig_as_C_string());
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   181
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   182
}
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
oop ResolvedMethodTable::add_method(const Method* method, Handle rmethod_name) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   185
  Thread* thread = Thread::current();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   186
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   187
  ResolvedMethodTableLookup lookup(thread, method_hash(method), method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   188
  ResolvedMethodGet rmg(thread, method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   189
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   190
  while (true) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   191
    if (_local_table->get(thread, lookup, rmg)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   192
      return rmg.get_res_oop();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   193
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   194
    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
   195
    // 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
   196
    if (_local_table->insert(thread, lookup, wh)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   197
      log_insert(method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   198
      return wh.resolve();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   199
    }
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   200
  }
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   201
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49594
diff changeset
   202
  return rmethod_name();
46505
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
bool ResolvedMethodTable::has_work() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   215
  return _has_work;
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
OopStorage* ResolvedMethodTable::weak_storage() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   219
  return _weak_handles;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   220
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   221
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   222
double ResolvedMethodTable::get_load_factor() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   223
  return (double)_items_count/_current_size;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   224
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   225
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   226
double ResolvedMethodTable::get_dead_factor() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   227
  return (double)_uncleaned_items_count/_current_size;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   228
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   229
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   230
static const double PREF_AVG_LIST_LEN = 2.0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   231
// 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
   232
static const double CLEAN_DEAD_HIGH_WATER_MARK = 0.5;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   233
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   234
void ResolvedMethodTable::check_concurrent_work() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   235
  if (_has_work) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   236
    return;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   237
  }
54431
ad9fa99fa48e 8221992: Fix old method replacement in ResolvedMethodTable
coleenp
parents: 53924
diff changeset
   238
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   239
  double load_factor = get_load_factor();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   240
  double dead_factor = get_dead_factor();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   241
  // We should clean/resize if we have more dead than alive,
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   242
  // more items than preferred load factor or
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   243
  // more dead items than water mark.
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   244
  if ((dead_factor > load_factor) ||
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   245
      (load_factor > PREF_AVG_LIST_LEN) ||
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   246
      (dead_factor > CLEAN_DEAD_HIGH_WATER_MARK)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   247
    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
   248
                                 load_factor, dead_factor);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   249
    trigger_concurrent_work();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   250
  }
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   251
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   252
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   253
void ResolvedMethodTable::trigger_concurrent_work() {
51472
eb97d1a319f9 8206423: Use locking for cleaning ResolvedMethodTable
pchilanomate
parents: 49982
diff changeset
   254
  MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   255
  _has_work = true;
51472
eb97d1a319f9 8206423: Use locking for cleaning ResolvedMethodTable
pchilanomate
parents: 49982
diff changeset
   256
  Service_lock->notify_all();
eb97d1a319f9 8206423: Use locking for cleaning ResolvedMethodTable
pchilanomate
parents: 49982
diff changeset
   257
}
eb97d1a319f9 8206423: Use locking for cleaning ResolvedMethodTable
pchilanomate
parents: 49982
diff changeset
   258
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   259
void ResolvedMethodTable::do_concurrent_work(JavaThread* jt) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   260
  _has_work = false;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   261
  double load_factor = get_load_factor();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   262
  log_debug(membername, table)("Concurrent work, live factor: %g", load_factor);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   263
  // We prefer growing, since that also removes dead items
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   264
  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
   265
    grow(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   266
  } else {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   267
    clean_dead_entries(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   268
  }
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
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   271
void ResolvedMethodTable::grow(JavaThread* jt) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   272
  ResolvedMethodTableHash::GrowTask gt(_local_table);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   273
  if (!gt.prepare(jt)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   274
    return;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   275
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   276
  log_trace(membername, table)("Started to grow");
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
    TraceTime timer("Grow", TRACETIME_LOG(Debug, membername, table, perf));
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   279
    while (gt.do_task(jt)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   280
      gt.pause(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   281
      {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   282
        ThreadBlockInVM tbivm(jt);
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   283
      }
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   284
      gt.cont(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   285
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   286
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   287
  gt.done(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   288
  _current_size = table_size();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   289
  log_info(membername, table)("Grown to size:" SIZE_FORMAT, _current_size);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   290
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   291
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   292
struct ResolvedMethodTableDoDelete : StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   293
  void operator()(WeakHandle<vm_resolved_method_table_data>* val) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   294
    /* do nothing */
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   295
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   296
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   297
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   298
struct ResolvedMethodTableDeleteCheck : StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   299
  long _count;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   300
  long _item;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   301
  ResolvedMethodTableDeleteCheck() : _count(0), _item(0) {}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   302
  bool operator()(WeakHandle<vm_resolved_method_table_data>* val) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   303
    ++_item;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   304
    oop tmp = val->peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   305
    if (tmp == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   306
      ++_count;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   307
      return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   308
    } else {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   309
      return false;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   310
    }
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   311
  }
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   312
};
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
void ResolvedMethodTable::clean_dead_entries(JavaThread* jt) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   315
  ResolvedMethodTableHash::BulkDeleteTask bdt(_local_table);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   316
  if (!bdt.prepare(jt)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   317
    return;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   318
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   319
  ResolvedMethodTableDeleteCheck stdc;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   320
  ResolvedMethodTableDoDelete stdd;
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
    TraceTime timer("Clean", TRACETIME_LOG(Debug, membername, table, perf));
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   323
    while(bdt.do_task(jt, stdc, stdd)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   324
      bdt.pause(jt);
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
        ThreadBlockInVM tbivm(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   327
      }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   328
      bdt.cont(jt);
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
    bdt.done(jt);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   331
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   332
  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
   333
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   334
void ResolvedMethodTable::reset_dead_counter() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   335
  _uncleaned_items_count = 0;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   336
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   337
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   338
void ResolvedMethodTable::inc_dead_counter(size_t ndead) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   339
  size_t total = Atomic::add(ndead, &_uncleaned_items_count);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   340
  log_trace(membername, table)(
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   341
     "Uncleaned items:" SIZE_FORMAT " added: " SIZE_FORMAT " total:" SIZE_FORMAT,
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   342
     _uncleaned_items_count, ndead, total);
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   343
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   344
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   345
// After the parallel walk this method must be called to trigger
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   346
// cleaning. Note it might trigger a resize instead.
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   347
void ResolvedMethodTable::finish_dead_counter() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   348
  check_concurrent_work();
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   349
}
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   350
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   351
#if INCLUDE_JVMTI
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   352
class AdjustMethodEntries : public StackObj {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   353
  bool* _trace_name_printed;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   354
public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   355
  AdjustMethodEntries(bool* trace_name_printed) : _trace_name_printed(trace_name_printed) {};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   356
  bool operator()(WeakHandle<vm_resolved_method_table_data>* entry) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   357
    oop mem_name = entry->peek();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   358
    if (mem_name == NULL) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   359
      // Removed
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   360
      return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   361
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   362
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   363
    Method* old_method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(mem_name);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   364
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   365
    if (old_method->is_old()) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   366
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   367
      Method* new_method = (old_method->is_deleted()) ?
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   368
                            Universe::throw_no_such_method_error() :
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   369
                            old_method->get_new_method();
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   370
      java_lang_invoke_ResolvedMethodName::set_vmtarget(mem_name, new_method);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   371
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   372
      ResourceMark rm;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   373
      if (!(*_trace_name_printed)) {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   374
        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
   375
         *_trace_name_printed = true;
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
      log_debug(redefine, class, update, constantpool)
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   378
        ("ResolvedMethod method update: %s(%s)",
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   379
         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
   380
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   381
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   382
    return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   383
  }
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
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   386
// It is called at safepoint only for RedefineClasses
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   387
void ResolvedMethodTable::adjust_method_entries(bool * trace_name_printed) {
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   388
  assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   389
  // For each entry in RMT, change to new method
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   390
  AdjustMethodEntries adjust(trace_name_printed);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   391
  _local_table->do_safepoint_scan(adjust);
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   392
}
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   393
#endif // INCLUDE_JVMTI
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   394
54574
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   395
// Verification
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   396
class VerifyResolvedMethod : StackObj {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   397
 public:
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   398
  bool operator()(WeakHandle<vm_resolved_method_table_data>* val) {
54574
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   399
    oop obj = val->peek();
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   400
    if (obj != NULL) {
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   401
      Method* method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(obj);
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   402
      guarantee(method->is_method(), "Must be");
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   403
      guarantee(!method->is_old(), "Must be");
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   404
    }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   405
    return true;
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   406
  };
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   407
};
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   408
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   409
size_t ResolvedMethodTable::items_count() {
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   410
  return _items_count;
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents:
diff changeset
   411
}
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   412
54574
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   413
void ResolvedMethodTable::verify() {
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   414
  VerifyResolvedMethod vcs;
7b74bbe5085b 8222558: Rework ResolvedMethodTable verification
stefank
parents: 54511
diff changeset
   415
  if (!_local_table->try_scan(Thread::current(), vcs)) {
54511
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   416
    log_info(membername, table)("verify unavailable at this moment");
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   417
  }
fbfcebad8e66 8221393: ResolvedMethodTable too small for StackWalking applications
stefank
parents: 54431
diff changeset
   418
}