annotate src/share/vm/classfile/dictionary.cpp @ 3011:f00918f35c7f

inlining and runtime interface related changes: added codeSize() and compilerStorage() to RiMethod HotSpotMethodResolved uses reflective methods instead of vmIds and survives compilations HotSpotResolvedType.isInitialized not represented as field (can change) inlining stores graphs into method objects and reuses them
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 16 Jun 2011 20:36:17 +0200
parents 1d1603768966
children b2cd0ee8f778
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2177
diff changeset
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1513
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1513
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1513
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/dictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "prims/jvmtiRedefineClassesTrace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "services/classLoadingService.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "utilities/hashtable.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 DictionaryEntry* Dictionary::_current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 int Dictionary::_current_class_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 Dictionary::Dictionary(int table_size)
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
39 : TwoOopHashtable<klassOop>(table_size, sizeof(DictionaryEntry)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
40 _current_class_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 _current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 };
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 Dictionary::Dictionary(int table_size, HashtableBucket* t,
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int number_of_entries)
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
48 : TwoOopHashtable<klassOop>(table_size, sizeof(DictionaryEntry), t, number_of_entries) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 _current_class_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 };
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 DictionaryEntry* Dictionary::new_entry(unsigned int hash, klassOop klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 oop loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 DictionaryEntry* entry;
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
57 entry = (DictionaryEntry*)Hashtable<klassOop>::new_entry(hash, klass);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58 entry->set_loader(loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 entry->set_pd_set(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 DictionaryEntry* Dictionary::new_entry() {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
65 DictionaryEntry* entry = (DictionaryEntry*)Hashtable<klassOop>::new_entry(0L, NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66 entry->set_loader(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 entry->set_pd_set(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 void Dictionary::free_entry(DictionaryEntry* entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // avoid recursion when deleting linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
74 while (entry->pd_set() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 ProtectionDomainEntry* to_delete = entry->pd_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 entry->set_pd_set(to_delete->next());
a61af66fc99e Initial load
duke
parents:
diff changeset
77 delete to_delete;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
79 Hashtable<klassOop>::free_entry(entry);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 bool DictionaryEntry::contains_protection_domain(oop protection_domain) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (protection_domain == instanceKlass::cast(klass())->protection_domain()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Ensure this doesn't show up in the pd_set (invariant)
a61af66fc99e Initial load
duke
parents:
diff changeset
87 bool in_pd_set = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 for (ProtectionDomainEntry* current = _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 current != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 current = current->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (current->protection_domain() == protection_domain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 in_pd_set = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (in_pd_set) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 assert(false, "A klass's protection domain should not show up "
a61af66fc99e Initial load
duke
parents:
diff changeset
98 "in its sys. dict. PD set");
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 #endif /* ASSERT */
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (protection_domain == instanceKlass::cast(klass())->protection_domain()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Succeeds trivially
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 for (ProtectionDomainEntry* current = _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 current != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 current = current->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (current->protection_domain() == protection_domain) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 void DictionaryEntry::add_protection_domain(oop protection_domain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 assert_locked_or_safepoint(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 if (!contains_protection_domain(protection_domain)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 ProtectionDomainEntry* new_head =
a61af66fc99e Initial load
duke
parents:
diff changeset
121 new ProtectionDomainEntry(protection_domain, _pd_set);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Warning: Preserve store ordering. The SystemDictionary is read
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // without locks. The new ProtectionDomainEntry must be
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // complete before other threads can be allowed to see it
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // via a store to _pd_set.
a61af66fc99e Initial load
duke
parents:
diff changeset
126 OrderAccess::release_store_ptr(&_pd_set, new_head);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (TraceProtectionDomainVerification && WizardMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 print();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 bool Dictionary::do_unloading(BoolObjectClosure* is_alive) {
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 710
diff changeset
135 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
136 bool class_was_unloaded = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 int index = 0; // Defined here for portability! Do not move
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Remove unloadable entries and classes from system dictionary
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // The placeholder array has been handled in always_strong_oops_do.
a61af66fc99e Initial load
duke
parents:
diff changeset
141 DictionaryEntry* probe = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 for (index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 probe = *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 klassOop e = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 instanceKlass* ik = instanceKlass::cast(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (ik->previous_versions() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // This klass has previous versions so see what we can cleanup
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // while it is safe to do so.
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 int gc_count = 0; // leave debugging breadcrumbs
a61af66fc99e Initial load
duke
parents:
diff changeset
154 int live_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // RC_TRACE macro has an embedded ResourceMark
a61af66fc99e Initial load
duke
parents:
diff changeset
157 RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
158 ik->external_name(), ik->previous_versions()->length()));
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // check the previous versions array for GC'ed weak refs
a61af66fc99e Initial load
duke
parents:
diff changeset
162 PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
47
2c106685d6d0 6497639: 4/3 Profiling Swing application caused JVM crash
dcubed
parents: 0
diff changeset
163 jobject cp_ref = pv_node->prev_constant_pool();
2c106685d6d0 6497639: 4/3 Profiling Swing application caused JVM crash
dcubed
parents: 0
diff changeset
164 assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (cp_ref == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 delete pv_node;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 ik->previous_versions()->remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Since we are traversing the array backwards, we don't have to
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // do anything special with the index.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 continue; // robustness
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (pvcp == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // this entry has been GC'ed so remove it
a61af66fc99e Initial load
duke
parents:
diff changeset
176 delete pv_node;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 ik->previous_versions()->remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Since we are traversing the array backwards, we don't have to
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // do anything special with the index.
a61af66fc99e Initial load
duke
parents:
diff changeset
180 gc_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (is_alive->do_object_b(pvcp)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 live_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 guarantee(false, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (method_refs != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 RC_TRACE(0x00000200, ("unload: previous methods length=%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
194 method_refs->length()));
a61af66fc99e Initial load
duke
parents:
diff changeset
195 for (int j = method_refs->length() - 1; j >= 0; j--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 jweak method_ref = method_refs->at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (method_ref == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 method_refs->remove_at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // Since we are traversing the array backwards, we don't have to
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // do anything special with the index.
a61af66fc99e Initial load
duke
parents:
diff changeset
202 continue; // robustness
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 methodOop method = (methodOop)JNIHandles::resolve(method_ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (method == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // this method entry has been GC'ed so remove it
a61af66fc99e Initial load
duke
parents:
diff changeset
208 JNIHandles::destroy_weak_global(method_ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 method_refs->remove_at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // RC_TRACE macro has an embedded ResourceMark
a61af66fc99e Initial load
duke
parents:
diff changeset
212 RC_TRACE(0x00000200,
a61af66fc99e Initial load
duke
parents:
diff changeset
213 ("unload: %s(%s): prev method @%d in version @%d is alive",
a61af66fc99e Initial load
duke
parents:
diff changeset
214 method->name()->as_C_string(),
a61af66fc99e Initial load
duke
parents:
diff changeset
215 method->signature()->as_C_string(), j, i));
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 assert(ik->previous_versions()->length() == live_count, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 RC_TRACE(0x00000200,
a61af66fc99e Initial load
duke
parents:
diff changeset
222 ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
223 gc_count));
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // Non-unloadable classes were handled in always_strong_oops_do
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (!is_strongly_reachable(class_loader, e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // Entry was not visited in phase1 (negated test from phase1)
a61af66fc99e Initial load
duke
parents:
diff changeset
229 assert(class_loader != NULL, "unloading entry with null class loader");
a61af66fc99e Initial load
duke
parents:
diff changeset
230 oop k_def_class_loader = ik->class_loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // Do we need to delete this system dictionary entry?
a61af66fc99e Initial load
duke
parents:
diff changeset
233 bool purge_entry = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // Do we need to delete this system dictionary entry?
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if (!is_alive->do_object_b(class_loader)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // If the loader is not live this entry should always be
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // removed (will never be looked up again). Note that this is
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // not the same as unloading the referred class.
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if (k_def_class_loader == class_loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // This is the defining entry, so the referred class is about
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // to be unloaded.
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // Notify the debugger and clean up the class.
a61af66fc99e Initial load
duke
parents:
diff changeset
244 guarantee(!is_alive->do_object_b(e),
a61af66fc99e Initial load
duke
parents:
diff changeset
245 "klass should not be live if defining loader is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
246 class_was_unloaded = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // notify the debugger
a61af66fc99e Initial load
duke
parents:
diff changeset
248 if (JvmtiExport::should_post_class_unload()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 JvmtiExport::post_class_unload(ik->as_klassOop());
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // notify ClassLoadingService of class unload
a61af66fc99e Initial load
duke
parents:
diff changeset
253 ClassLoadingService::notify_class_unloaded(ik);
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // Clean up C heap
a61af66fc99e Initial load
duke
parents:
diff changeset
256 ik->release_C_heap_structures();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // Also remove this system dictionary entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 purge_entry = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // The loader in this entry is alive. If the klass is dead,
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // the loader must be an initiating loader (rather than the
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // defining loader). Remove this entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (!is_alive->do_object_b(e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 guarantee(!is_alive->do_object_b(k_def_class_loader),
a61af66fc99e Initial load
duke
parents:
diff changeset
267 "defining loader should not be live if klass is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // If we get here, the class_loader must not be the defining
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // loader, it must be an initiating one.
a61af66fc99e Initial load
duke
parents:
diff changeset
270 assert(k_def_class_loader != class_loader,
a61af66fc99e Initial load
duke
parents:
diff changeset
271 "cannot have live defining loader and unreachable klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // Loader is live, but class and its defining loader are dead.
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // Remove the entry. The class is going away.
a61af66fc99e Initial load
duke
parents:
diff changeset
275 purge_entry = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (purge_entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 *p = probe->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 if (probe == _current_class_entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 _current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284 free_entry(probe);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 p = probe->next_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 return class_was_unloaded;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 void Dictionary::always_strong_classes_do(OopClosure* blk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // Follow all system classes and temporary placeholders in dictionary
a61af66fc99e Initial load
duke
parents:
diff changeset
297 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 for (DictionaryEntry *probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 probe = probe->next()) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
301 klassOop e = probe->klass();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
302 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 if (is_strongly_reachable(class_loader, e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 blk->do_oop((oop*)probe->klass_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
305 if (class_loader != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 blk->do_oop(probe->loader_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308 probe->protection_domain_set_oops_do(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // Just the classes from defining class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
316 void Dictionary::classes_do(void f(klassOop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
322 if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 f(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // Added for initialize_itable_for_klass to handle exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // Just the classes from defining class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
331 void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
337 if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 f(k, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // All classes, and their class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // (added for helpers that use HandleMarks and ResourceMarks)
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // Don't iterate over placeholders
a61af66fc99e Initial load
duke
parents:
diff changeset
348 void Dictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
354 f(k, probe->loader(), CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // All classes, and their class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // Don't iterate over placeholders
a61af66fc99e Initial load
duke
parents:
diff changeset
362 void Dictionary::classes_do(void f(klassOop, oop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
365 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
366 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
368 f(k, probe->loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 void Dictionary::oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 f->do_oop((oop*)probe->klass_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (probe->loader() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 f->do_oop(probe->loader_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 probe->protection_domain_set_oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 void Dictionary::methods_do(void f(methodOop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
392 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
393 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
395 if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // only take klass is we have the entry with the defining class loader
a61af66fc99e Initial load
duke
parents:
diff changeset
397 instanceKlass::cast(k)->methods_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 klassOop Dictionary::try_get_next_class() {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 if (_current_class_entry != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 klassOop k = _current_class_entry->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
408 _current_class_entry = _current_class_entry->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
409 return k;
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411 _current_class_index = (_current_class_index + 1) % table_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
412 _current_class_entry = bucket(_current_class_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // never reached
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // Add a loaded class to the system dictionary.
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // Readers of the SystemDictionary aren't always locked, so _buckets
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // is volatile. The store of the next field in the constructor is
a61af66fc99e Initial load
duke
parents:
diff changeset
421 // also cast to volatile; we do this to ensure store order is maintained
a61af66fc99e Initial load
duke
parents:
diff changeset
422 // by the compilers.
a61af66fc99e Initial load
duke
parents:
diff changeset
423
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
424 void Dictionary::add_klass(Symbol* class_name, Handle class_loader,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
425 KlassHandle obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 assert_locked_or_safepoint(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 assert(obj() != NULL, "adding NULL obj");
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
428 assert(Klass::cast(obj())->name() == class_name, "sanity check on name");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 unsigned int hash = compute_hash(class_name, class_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
431 int index = hash_to_index(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
432 DictionaryEntry* entry = new_entry(hash, obj(), class_loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
433 add_entry(index, entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // This routine does not lock the system dictionary.
a61af66fc99e Initial load
duke
parents:
diff changeset
438 //
a61af66fc99e Initial load
duke
parents:
diff changeset
439 // Since readers don't hold a lock, we must make sure that system
a61af66fc99e Initial load
duke
parents:
diff changeset
440 // dictionary entries are only removed at a safepoint (when only one
a61af66fc99e Initial load
duke
parents:
diff changeset
441 // thread is running), and are added to in a safe way (all links must
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // be updated in an MT-safe manner).
a61af66fc99e Initial load
duke
parents:
diff changeset
443 //
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // Callers should be aware that an entry could be added just after
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // _buckets[index] is read here, so the caller will not see the new entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
446 DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
447 Symbol* class_name,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
448 Handle class_loader) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
449 oop loader = class_loader();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
450 debug_only(_lookup_count++);
a61af66fc99e Initial load
duke
parents:
diff changeset
451 for (DictionaryEntry* entry = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 entry != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 entry = entry->next()) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
454 if (entry->hash() == hash && entry->equals(class_name, loader)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
455 return entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457 debug_only(_lookup_length++);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
463 klassOop Dictionary::find(int index, unsigned int hash, Symbol* name,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
464 Handle loader, Handle protection_domain, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 DictionaryEntry* entry = get_entry(index, hash, name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
466 if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 return entry->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
468 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
469 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
470 }
a61af66fc99e Initial load
duke
parents:
diff changeset
471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
472
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 klassOop Dictionary::find_class(int index, unsigned int hash,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
475 Symbol* name, Handle loader) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
476 assert_locked_or_safepoint(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
477 assert (index == index_for(name, loader), "incorrect index?");
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 DictionaryEntry* entry = get_entry(index, hash, name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
480 return (entry != NULL) ? entry->klass() : (klassOop)NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // Variant of find_class for shared classes. No locking required, as
a61af66fc99e Initial load
duke
parents:
diff changeset
485 // that table is static.
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 klassOop Dictionary::find_shared_class(int index, unsigned int hash,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
488 Symbol* name) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
489 assert (index == index_for(name, Handle()), "incorrect index?");
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 DictionaryEntry* entry = get_entry(index, hash, name, Handle());
a61af66fc99e Initial load
duke
parents:
diff changeset
492 return (entry != NULL) ? entry->klass() : (klassOop)NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
493 }
a61af66fc99e Initial load
duke
parents:
diff changeset
494
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 void Dictionary::add_protection_domain(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
497 instanceKlassHandle klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
498 Handle loader, Handle protection_domain,
a61af66fc99e Initial load
duke
parents:
diff changeset
499 TRAPS) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
500 Symbol* klass_name = klass->name();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
501 DictionaryEntry* entry = get_entry(index, hash, klass_name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
502
a61af66fc99e Initial load
duke
parents:
diff changeset
503 assert(entry != NULL,"entry must be present, we just created it");
a61af66fc99e Initial load
duke
parents:
diff changeset
504 assert(protection_domain() != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
505 "real protection domain should be present");
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 entry->add_protection_domain(protection_domain());
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 assert(entry->contains_protection_domain(protection_domain()),
a61af66fc99e Initial load
duke
parents:
diff changeset
510 "now protection domain should be present");
a61af66fc99e Initial load
duke
parents:
diff changeset
511 }
a61af66fc99e Initial load
duke
parents:
diff changeset
512
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
515 Symbol* name,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
516 Handle loader,
a61af66fc99e Initial load
duke
parents:
diff changeset
517 Handle protection_domain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 DictionaryEntry* entry = get_entry(index, hash, name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
519 return entry->is_valid_protection_domain(protection_domain);
a61af66fc99e Initial load
duke
parents:
diff changeset
520 }
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 void Dictionary::reorder_dictionary() {
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // Copy all the dictionary entries into a single master list.
a61af66fc99e Initial load
duke
parents:
diff changeset
526
a61af66fc99e Initial load
duke
parents:
diff changeset
527 DictionaryEntry* master_list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
528 for (int i = 0; i < table_size(); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 DictionaryEntry* p = bucket(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 while (p != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
531 DictionaryEntry* tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
532 tmp = p->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
533 p->set_next(master_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
534 master_list = p;
a61af66fc99e Initial load
duke
parents:
diff changeset
535 p = tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
537 set_entry(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // Add the dictionary entries back to the list in the correct buckets.
a61af66fc99e Initial load
duke
parents:
diff changeset
541 Thread *thread = Thread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
542
a61af66fc99e Initial load
duke
parents:
diff changeset
543 while (master_list != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
544 DictionaryEntry* p = master_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
545 master_list = master_list->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
546 p->set_next(NULL);
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
547 Symbol* class_name = instanceKlass::cast((klassOop)(p->klass()))->name();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
548 unsigned int hash = compute_hash(class_name, Handle(thread, p->loader()));
a61af66fc99e Initial load
duke
parents:
diff changeset
549 int index = hash_to_index(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
550 p->set_hash(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
551 p->set_next(bucket(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
552 set_entry(index, p);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
556 SymbolPropertyTable::SymbolPropertyTable(int table_size)
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
557 : Hashtable<Symbol*>(table_size, sizeof(SymbolPropertyEntry))
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
558 {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
559 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
560 SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket* t,
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
561 int number_of_entries)
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
562 : Hashtable<Symbol*>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries)
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
563 {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
564 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
565
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
566
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
567 SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
568 Symbol* sym,
1507
cd5dbf694d45 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 710
diff changeset
569 intptr_t sym_mode) {
cd5dbf694d45 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 710
diff changeset
570 assert(index == index_for(sym, sym_mode), "incorrect index?");
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
571 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
572 if (p->hash() == hash && p->symbol() == sym && p->symbol_mode() == sym_mode) {
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
573 return p;
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
574 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
575 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
576 return NULL;
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
577 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
578
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
579
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
580 SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash,
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
581 Symbol* sym, intptr_t sym_mode) {
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
582 assert_locked_or_safepoint(SystemDictionary_lock);
1507
cd5dbf694d45 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 710
diff changeset
583 assert(index == index_for(sym, sym_mode), "incorrect index?");
cd5dbf694d45 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 710
diff changeset
584 assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry");
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
585
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
586 SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode);
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
587 Hashtable<Symbol*>::add_entry(index, p);
710
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
588 return p;
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
589 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
590
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
591
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
592 void SymbolPropertyTable::oops_do(OopClosure* f) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
593 for (int index = 0; index < table_size(); index++) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
594 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
595 if (p->property_oop() != NULL) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
596 f->do_oop(p->property_oop_addr());
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
597 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
598 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
599 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
600 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
601
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
602 void SymbolPropertyTable::methods_do(void f(methodOop)) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
603 for (int index = 0; index < table_size(); index++) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
604 for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
605 oop prop = p->property_oop();
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
606 if (prop != NULL && prop->is_method()) {
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
607 f((methodOop)prop);
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
608 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
609 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
610 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
611 }
e5b0439ef4ae 6655638: dynamic languages need method handles
jrose
parents: 196
diff changeset
612
0
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // ----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
615 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 void Dictionary::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
618 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
619 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
620
a61af66fc99e Initial load
duke
parents:
diff changeset
621 tty->print_cr("Java system dictionary (classes=%d)", number_of_entries());
a61af66fc99e Initial load
duke
parents:
diff changeset
622 tty->print_cr("^ indicates that initiating loader is different from "
a61af66fc99e Initial load
duke
parents:
diff changeset
623 "defining loader");
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
627 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
628 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 if (Verbose) tty->print("%4d: ", index);
a61af66fc99e Initial load
duke
parents:
diff changeset
630 klassOop e = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
631 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
632 bool is_defining_class =
a61af66fc99e Initial load
duke
parents:
diff changeset
633 (class_loader == instanceKlass::cast(e)->class_loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
634 tty->print("%s%s", is_defining_class ? " " : "^",
a61af66fc99e Initial load
duke
parents:
diff changeset
635 Klass::cast(e)->external_name());
a61af66fc99e Initial load
duke
parents:
diff changeset
636 if (class_loader != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 tty->print(", loader ");
a61af66fc99e Initial load
duke
parents:
diff changeset
638 class_loader->print_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
640 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
641 }
a61af66fc99e Initial load
duke
parents:
diff changeset
642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
646
a61af66fc99e Initial load
duke
parents:
diff changeset
647 void Dictionary::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
649 int element_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
650 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
651 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
652 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
653 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
654 klassOop e = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
655 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
656 guarantee(Klass::cast(e)->oop_is_instance(),
a61af66fc99e Initial load
duke
parents:
diff changeset
657 "Verify of system dictionary failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
658 // class loader must be present; a null class loader is the
a61af66fc99e Initial load
duke
parents:
diff changeset
659 // boostrap loader
a61af66fc99e Initial load
duke
parents:
diff changeset
660 guarantee(class_loader == NULL || class_loader->is_instance(),
a61af66fc99e Initial load
duke
parents:
diff changeset
661 "checking type of class_loader");
a61af66fc99e Initial load
duke
parents:
diff changeset
662 e->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
663 probe->verify_protection_domain_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
664 element_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
665 }
a61af66fc99e Initial load
duke
parents:
diff changeset
666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
667 guarantee(number_of_entries() == element_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
668 "Verify of system dictionary failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
669 debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
a61af66fc99e Initial load
duke
parents:
diff changeset
670 }