src/hotspot/share/classfile/resolutionErrors.cpp
author stuefe
Tue, 26 Nov 2019 16:21:29 +0100
branchstuefe-new-metaspace-branch
changeset 59272 54750b448264
parent 51486 67b55f3c45eb
permissions -rw-r--r--
Metadatatype back to metaspace.hpp to reduce patch size
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/resolutionErrors.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/safepoint.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/hashtable.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// add new entry to the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
void ResolutionErrorTable::add_entry(int index, unsigned int hash,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 24334
diff changeset
    35
                                     const constantPoolHandle& pool, int cp_index,
24334
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    36
                                     Symbol* error, Symbol* message)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert_locked_or_safepoint(SystemDictionary_lock);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    39
  assert(!pool.is_null() && error != NULL, "adding NULL obj");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
24334
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    41
  ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error, message);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  add_entry(index, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// find entry in the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 24334
diff changeset
    47
                                                       const constantPoolHandle& pool, int cp_index)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  assert_locked_or_safepoint(SystemDictionary_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  for (ResolutionErrorEntry *error_probe = bucket(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                         error_probe != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                         error_probe = error_probe->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  if (error_probe->hash() == hash && error_probe->pool() == pool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      return error_probe;;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    61
void ResolutionErrorEntry::set_error(Symbol* e) {
24334
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    62
  assert(e != NULL, "must set a value");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    63
  _error = e;
24334
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    64
  _error->increment_refcount();
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    65
}
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    66
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    67
void ResolutionErrorEntry::set_message(Symbol* c) {
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    68
  _message = c;
51486
67b55f3c45eb 8208172: SIGSEGV when owner of invokedynamic bootstrap method throws an exception - Symbol::increment_refcount()+0x0
coleenp
parents: 51375
diff changeset
    69
  if (_message != NULL) {
67b55f3c45eb 8208172: SIGSEGV when owner of invokedynamic bootstrap method throws an exception - Symbol::increment_refcount()+0x0
coleenp
parents: 51375
diff changeset
    70
    _message->increment_refcount();
67b55f3c45eb 8208172: SIGSEGV when owner of invokedynamic bootstrap method throws an exception - Symbol::increment_refcount()+0x0
coleenp
parents: 51375
diff changeset
    71
  }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    72
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    73
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
// create new error entry
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    75
ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
24334
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    76
                                                      int cp_index, Symbol* error,
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    77
                                                      Symbol* message)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
{
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    79
  ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  entry->set_cp_index(cp_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  entry->set_error(error);
24334
36096f7271f4 8023697: failed class resolution reports different class name in detail message for the first and subsequent times
coleenp
parents: 13728
diff changeset
    82
  entry->set_message(message);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    87
void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    88
  // decrement error refcount
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    89
  assert(entry->error() != NULL, "error should be set");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    90
  entry->error()->decrement_refcount();
51486
67b55f3c45eb 8208172: SIGSEGV when owner of invokedynamic bootstrap method throws an exception - Symbol::increment_refcount()+0x0
coleenp
parents: 51375
diff changeset
    91
  if (entry->message() != NULL) {
67b55f3c45eb 8208172: SIGSEGV when owner of invokedynamic bootstrap method throws an exception - Symbol::increment_refcount()+0x0
coleenp
parents: 51375
diff changeset
    92
    entry->message()->decrement_refcount();
67b55f3c45eb 8208172: SIGSEGV when owner of invokedynamic bootstrap method throws an exception - Symbol::increment_refcount()+0x0
coleenp
parents: 51375
diff changeset
    93
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    94
  Hashtable<ConstantPool*, mtClass>::free_entry(entry);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    95
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    96
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    97
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// create resolution error table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
ResolutionErrorTable::ResolutionErrorTable(int table_size)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   100
    : Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   103
// RedefineClasses support - remove matching entry of a
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   104
// constant pool that is going away
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   105
void ResolutionErrorTable::delete_entry(ConstantPool* c) {
51375
b812a85b3aa4 8207778: Add locking to ModuleEntry and PackageEntry tables
hseigel
parents: 49821
diff changeset
   106
  assert_locked_or_safepoint(SystemDictionary_lock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  for (int i = 0; i < table_size(); i++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   108
    for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   109
      ResolutionErrorEntry* entry = *p;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   110
      assert(entry->pool() != NULL, "resolution error table is corrupt");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   111
      if (entry->pool() == c) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   112
        *p = entry->next();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   113
        free_entry(entry);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   114
      } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   115
        p = entry->next_addr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   116
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// Remove unloaded entries from the table
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   123
void ResolutionErrorTable::purge_resolution_errors() {
51375
b812a85b3aa4 8207778: Add locking to ModuleEntry and PackageEntry tables
hseigel
parents: 49821
diff changeset
   124
  assert_locked_or_safepoint(SystemDictionary_lock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  for (int i = 0; i < table_size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      ResolutionErrorEntry* entry = *p;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   128
      assert(entry->pool() != (ConstantPool*)NULL, "resolution error table is corrupt");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   129
      ConstantPool* pool = entry->pool();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   130
      assert(pool->pool_holder() != NULL, "Constant pool without a class?");
49821
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   131
02c08e20d66c 8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents: 47216
diff changeset
   132
      if (pool->pool_holder()->is_loader_alive()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        p = entry->next_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        *p = entry->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        free_entry(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}