jdk

Форк
0
/
resolutionErrors.cpp 
174 строки · 5.7 Кб
1
/*
2
 * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 *
23
 */
24

25
#include "precompiled.hpp"
26
#include "classfile/resolutionErrors.hpp"
27
#include "memory/allocation.hpp"
28
#include "oops/constantPool.hpp"
29
#include "oops/instanceKlass.hpp"
30
#include "oops/klass.inline.hpp"
31
#include "oops/symbol.hpp"
32
#include "runtime/handles.inline.hpp"
33
#include "runtime/mutexLocker.hpp"
34
#include "utilities/resourceHash.hpp"
35

36
class ResolutionErrorKey {
37
  ConstantPool* _cpool;
38
  int           _index;
39

40
 public:
41
  ResolutionErrorKey(ConstantPool* cpool, int index) : _cpool(cpool), _index(index) {
42
    assert(_index > 0, "should be already encoded or otherwise greater than zero");
43
  }
44

45
  ConstantPool* cpool() const { return _cpool; }
46

47
  static unsigned hash(const ResolutionErrorKey& key) {
48
    Symbol* name = key._cpool->pool_holder()->name();
49
    return (unsigned int)(name->identity_hash() ^ key._index);
50
  }
51

52
  static bool equals(const ResolutionErrorKey& l, const ResolutionErrorKey& r) {
53
    return (l._cpool == r._cpool) && (l._index == r._index);
54
  }
55
};
56

57
using InternalResolutionErrorTable = ResourceHashtable<ResolutionErrorKey, ResolutionErrorEntry*, 107, AnyObj::C_HEAP, mtClass,
58
                  ResolutionErrorKey::hash,
59
                  ResolutionErrorKey::equals>;
60

61
static InternalResolutionErrorTable* _resolution_error_table;
62

63
void ResolutionErrorTable::initialize() {
64
  _resolution_error_table = new (mtClass) InternalResolutionErrorTable();
65
}
66

67
// create new error entry
68
void ResolutionErrorTable::add_entry(const constantPoolHandle& pool, int cp_index,
69
                                     Symbol* error, const char* message,
70
                                     Symbol* cause, const char* cause_msg)
71
{
72
  assert_locked_or_safepoint(SystemDictionary_lock);
73
  assert(!pool.is_null() && error != nullptr, "adding null obj");
74

75
  ResolutionErrorKey key(pool(), cp_index);
76
  ResolutionErrorEntry *entry = new ResolutionErrorEntry(error, message, cause, cause_msg);
77
  _resolution_error_table->put(key, entry);
78
}
79

80
// create new nest host error entry
81
void ResolutionErrorTable::add_entry(const constantPoolHandle& pool, int cp_index,
82
                                     const char* message)
83
{
84
  assert_locked_or_safepoint(SystemDictionary_lock);
85
  assert(!pool.is_null() && message != nullptr, "adding null obj");
86

87
  ResolutionErrorKey key(pool(), cp_index);
88
  ResolutionErrorEntry *entry = new ResolutionErrorEntry(message);
89
  _resolution_error_table->put(key, entry);
90
}
91

92
// find entry in the table
93
ResolutionErrorEntry* ResolutionErrorTable::find_entry(const constantPoolHandle& pool, int cp_index) {
94
  assert_locked_or_safepoint(SystemDictionary_lock);
95
  ResolutionErrorKey key(pool(), cp_index);
96
  ResolutionErrorEntry** entry = _resolution_error_table->get(key);
97
  return entry == nullptr ? nullptr : *entry;
98
}
99

100
ResolutionErrorEntry::ResolutionErrorEntry(Symbol* error, const char* message,
101
                                           Symbol* cause, const char* cause_msg):
102
        _error(error),
103
        _message(message != nullptr ? os::strdup(message) : nullptr),
104
        _cause(cause),
105
        _cause_msg(cause_msg != nullptr ? os::strdup(cause_msg) : nullptr),
106
        _nest_host_error(nullptr) {
107

108
  Symbol::maybe_increment_refcount(_error);
109
  Symbol::maybe_increment_refcount(_cause);
110
}
111

112
ResolutionErrorEntry::~ResolutionErrorEntry() {
113
  // decrement error refcount
114
  Symbol::maybe_decrement_refcount(_error);
115
  Symbol::maybe_decrement_refcount(_cause);
116

117
  if (_message != nullptr) {
118
    FREE_C_HEAP_ARRAY(char, _message);
119
  }
120

121
  if (_cause_msg != nullptr) {
122
    FREE_C_HEAP_ARRAY(char, _cause_msg);
123
  }
124

125
  if (nest_host_error() != nullptr) {
126
    FREE_C_HEAP_ARRAY(char, nest_host_error());
127
  }
128
}
129

130
class ResolutionErrorDeleteIterate : StackObj {
131
  ConstantPool* p;
132

133
public:
134
  ResolutionErrorDeleteIterate(ConstantPool* pool):
135
    p(pool) {};
136

137
  bool do_entry(const ResolutionErrorKey& key, ResolutionErrorEntry* value){
138
    if (key.cpool() == p) {
139
      delete value;
140
      return true;
141
    } else {
142
      return false;
143
    }
144
  }
145
};
146

147
// Delete entries in the table that match with ConstantPool c
148
void ResolutionErrorTable::delete_entry(ConstantPool* c) {
149
  assert_locked_or_safepoint(SystemDictionary_lock);
150

151
  ResolutionErrorDeleteIterate deleteIterator(c);
152
  _resolution_error_table->unlink(&deleteIterator);
153
}
154

155
class ResolutionIteratePurgeErrors : StackObj {
156
public:
157
  bool do_entry(const ResolutionErrorKey& key, ResolutionErrorEntry* value){
158
    ConstantPool* pool = key.cpool();
159
    if (!(pool->pool_holder()->is_loader_alive())) {
160
      delete value;
161
      return true;
162
    } else {
163
      return false;
164
    }
165
  }
166
};
167

168
// Remove unloaded entries from the table
169
void ResolutionErrorTable::purge_resolution_errors() {
170
  assert_locked_or_safepoint(SystemDictionary_lock);
171

172
  ResolutionIteratePurgeErrors purgeErrorsIterator;
173
  _resolution_error_table->unlink(&purgeErrorsIterator);
174
}
175

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.