annotate src/share/vm/classfile/dictionary.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents 2c106685d6d0
children e5b0439ef4ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 47
diff changeset
2 * Copyright 2003-2008 Sun Microsystems, Inc. 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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_dictionary.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 DictionaryEntry* Dictionary::_current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 int Dictionary::_current_class_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 Dictionary::Dictionary(int table_size)
a61af66fc99e Initial load
duke
parents:
diff changeset
34 : TwoOopHashtable(table_size, sizeof(DictionaryEntry)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 _current_class_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 _current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 };
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 Dictionary::Dictionary(int table_size, HashtableBucket* t,
a61af66fc99e Initial load
duke
parents:
diff changeset
42 int number_of_entries)
a61af66fc99e Initial load
duke
parents:
diff changeset
43 : TwoOopHashtable(table_size, sizeof(DictionaryEntry), t, number_of_entries) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _current_class_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 };
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 DictionaryEntry* Dictionary::new_entry(unsigned int hash, klassOop klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
50 oop loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 DictionaryEntry* entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 entry = (DictionaryEntry*)Hashtable::new_entry(hash, klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 entry->set_loader(loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 entry->set_pd_set(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 DictionaryEntry* Dictionary::new_entry() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 DictionaryEntry* entry = (DictionaryEntry*)Hashtable::new_entry(0L, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 entry->set_loader(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 entry->set_pd_set(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void Dictionary::free_entry(DictionaryEntry* entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // avoid recursion when deleting linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
69 while (entry->pd_set() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 ProtectionDomainEntry* to_delete = entry->pd_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
71 entry->set_pd_set(to_delete->next());
a61af66fc99e Initial load
duke
parents:
diff changeset
72 delete to_delete;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 Hashtable::free_entry(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 bool DictionaryEntry::contains_protection_domain(oop protection_domain) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (protection_domain == instanceKlass::cast(klass())->protection_domain()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Ensure this doesn't show up in the pd_set (invariant)
a61af66fc99e Initial load
duke
parents:
diff changeset
82 bool in_pd_set = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 for (ProtectionDomainEntry* current = _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 current != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 current = current->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (current->protection_domain() == protection_domain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 in_pd_set = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (in_pd_set) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 assert(false, "A klass's protection domain should not show up "
a61af66fc99e Initial load
duke
parents:
diff changeset
93 "in its sys. dict. PD set");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 #endif /* ASSERT */
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (protection_domain == instanceKlass::cast(klass())->protection_domain()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Succeeds trivially
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 for (ProtectionDomainEntry* current = _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 current != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 current = current->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (current->protection_domain() == protection_domain) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void DictionaryEntry::add_protection_domain(oop protection_domain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 assert_locked_or_safepoint(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (!contains_protection_domain(protection_domain)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 ProtectionDomainEntry* new_head =
a61af66fc99e Initial load
duke
parents:
diff changeset
116 new ProtectionDomainEntry(protection_domain, _pd_set);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Warning: Preserve store ordering. The SystemDictionary is read
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // without locks. The new ProtectionDomainEntry must be
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // complete before other threads can be allowed to see it
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // via a store to _pd_set.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 OrderAccess::release_store_ptr(&_pd_set, new_head);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (TraceProtectionDomainVerification && WizardMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 print();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 bool Dictionary::do_unloading(BoolObjectClosure* is_alive) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint")
a61af66fc99e Initial load
duke
parents:
diff changeset
131 bool class_was_unloaded = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 int index = 0; // Defined here for portability! Do not move
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Remove unloadable entries and classes from system dictionary
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // The placeholder array has been handled in always_strong_oops_do.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 DictionaryEntry* probe = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 for (index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 probe = *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 klassOop e = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 instanceKlass* ik = instanceKlass::cast(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (ik->previous_versions() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // This klass has previous versions so see what we can cleanup
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // while it is safe to do so.
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 int gc_count = 0; // leave debugging breadcrumbs
a61af66fc99e Initial load
duke
parents:
diff changeset
149 int live_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // RC_TRACE macro has an embedded ResourceMark
a61af66fc99e Initial load
duke
parents:
diff changeset
152 RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
153 ik->external_name(), ik->previous_versions()->length()));
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // check the previous versions array for GC'ed weak refs
a61af66fc99e Initial load
duke
parents:
diff changeset
157 PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
47
2c106685d6d0 6497639: 4/3 Profiling Swing application caused JVM crash
dcubed
parents: 0
diff changeset
158 jobject cp_ref = pv_node->prev_constant_pool();
2c106685d6d0 6497639: 4/3 Profiling Swing application caused JVM crash
dcubed
parents: 0
diff changeset
159 assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (cp_ref == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 delete pv_node;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 ik->previous_versions()->remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Since we are traversing the array backwards, we don't have to
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // do anything special with the index.
a61af66fc99e Initial load
duke
parents:
diff changeset
165 continue; // robustness
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 constantPoolOop pvcp = (constantPoolOop)JNIHandles::resolve(cp_ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (pvcp == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // this entry has been GC'ed so remove it
a61af66fc99e Initial load
duke
parents:
diff changeset
171 delete pv_node;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 ik->previous_versions()->remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Since we are traversing the array backwards, we don't have to
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // do anything special with the index.
a61af66fc99e Initial load
duke
parents:
diff changeset
175 gc_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (is_alive->do_object_b(pvcp)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 live_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 guarantee(false, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 if (method_refs != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 RC_TRACE(0x00000200, ("unload: previous methods length=%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
189 method_refs->length()));
a61af66fc99e Initial load
duke
parents:
diff changeset
190 for (int j = method_refs->length() - 1; j >= 0; j--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 jweak method_ref = method_refs->at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 if (method_ref == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 method_refs->remove_at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Since we are traversing the array backwards, we don't have to
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // do anything special with the index.
a61af66fc99e Initial load
duke
parents:
diff changeset
197 continue; // robustness
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 methodOop method = (methodOop)JNIHandles::resolve(method_ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (method == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // this method entry has been GC'ed so remove it
a61af66fc99e Initial load
duke
parents:
diff changeset
203 JNIHandles::destroy_weak_global(method_ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 method_refs->remove_at(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // RC_TRACE macro has an embedded ResourceMark
a61af66fc99e Initial load
duke
parents:
diff changeset
207 RC_TRACE(0x00000200,
a61af66fc99e Initial load
duke
parents:
diff changeset
208 ("unload: %s(%s): prev method @%d in version @%d is alive",
a61af66fc99e Initial load
duke
parents:
diff changeset
209 method->name()->as_C_string(),
a61af66fc99e Initial load
duke
parents:
diff changeset
210 method->signature()->as_C_string(), j, i));
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 assert(ik->previous_versions()->length() == live_count, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
216 RC_TRACE(0x00000200,
a61af66fc99e Initial load
duke
parents:
diff changeset
217 ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
218 gc_count));
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Non-unloadable classes were handled in always_strong_oops_do
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (!is_strongly_reachable(class_loader, e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // Entry was not visited in phase1 (negated test from phase1)
a61af66fc99e Initial load
duke
parents:
diff changeset
224 assert(class_loader != NULL, "unloading entry with null class loader");
a61af66fc99e Initial load
duke
parents:
diff changeset
225 oop k_def_class_loader = ik->class_loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // Do we need to delete this system dictionary entry?
a61af66fc99e Initial load
duke
parents:
diff changeset
228 bool purge_entry = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // Do we need to delete this system dictionary entry?
a61af66fc99e Initial load
duke
parents:
diff changeset
231 if (!is_alive->do_object_b(class_loader)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // If the loader is not live this entry should always be
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // removed (will never be looked up again). Note that this is
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // not the same as unloading the referred class.
a61af66fc99e Initial load
duke
parents:
diff changeset
235 if (k_def_class_loader == class_loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // This is the defining entry, so the referred class is about
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // to be unloaded.
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // Notify the debugger and clean up the class.
a61af66fc99e Initial load
duke
parents:
diff changeset
239 guarantee(!is_alive->do_object_b(e),
a61af66fc99e Initial load
duke
parents:
diff changeset
240 "klass should not be live if defining loader is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
241 class_was_unloaded = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // notify the debugger
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (JvmtiExport::should_post_class_unload()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 JvmtiExport::post_class_unload(ik->as_klassOop());
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // notify ClassLoadingService of class unload
a61af66fc99e Initial load
duke
parents:
diff changeset
248 ClassLoadingService::notify_class_unloaded(ik);
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Clean up C heap
a61af66fc99e Initial load
duke
parents:
diff changeset
251 ik->release_C_heap_structures();
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // Also remove this system dictionary entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 purge_entry = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // The loader in this entry is alive. If the klass is dead,
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // the loader must be an initiating loader (rather than the
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // defining loader). Remove this entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (!is_alive->do_object_b(e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 guarantee(!is_alive->do_object_b(k_def_class_loader),
a61af66fc99e Initial load
duke
parents:
diff changeset
262 "defining loader should not be live if klass is not");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // If we get here, the class_loader must not be the defining
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // loader, it must be an initiating one.
a61af66fc99e Initial load
duke
parents:
diff changeset
265 assert(k_def_class_loader != class_loader,
a61af66fc99e Initial load
duke
parents:
diff changeset
266 "cannot have live defining loader and unreachable klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // Loader is live, but class and its defining loader are dead.
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // Remove the entry. The class is going away.
a61af66fc99e Initial load
duke
parents:
diff changeset
270 purge_entry = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 if (purge_entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 *p = probe->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
276 if (probe == _current_class_entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 _current_class_entry = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 free_entry(probe);
a61af66fc99e Initial load
duke
parents:
diff changeset
280 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 p = probe->next_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286 return class_was_unloaded;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 void Dictionary::always_strong_classes_do(OopClosure* blk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // Follow all system classes and temporary placeholders in dictionary
a61af66fc99e Initial load
duke
parents:
diff changeset
292 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 for (DictionaryEntry *probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 oop e = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
297 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (is_strongly_reachable(class_loader, e)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 blk->do_oop((oop*)probe->klass_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
300 if (class_loader != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 blk->do_oop(probe->loader_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303 probe->protection_domain_set_oops_do(blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // Just the classes from defining class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
311 void Dictionary::classes_do(void f(klassOop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
313 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
314 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
315 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 f(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 }
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Added for initialize_itable_for_klass to handle exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
325 // Just the classes from defining class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
326 void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
332 if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 f(k, CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // All classes, and their class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // (added for helpers that use HandleMarks and ResourceMarks)
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // Don't iterate over placeholders
a61af66fc99e Initial load
duke
parents:
diff changeset
343 void Dictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
348 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
349 f(k, probe->loader(), CHECK);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // All classes, and their class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // Don't iterate over placeholders
a61af66fc99e Initial load
duke
parents:
diff changeset
357 void Dictionary::classes_do(void f(klassOop, oop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 f(k, probe->loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368
a61af66fc99e Initial load
duke
parents:
diff changeset
369 void Dictionary::oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 f->do_oop((oop*)probe->klass_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (probe->loader() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 f->do_oop(probe->loader_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378 probe->protection_domain_set_oops_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 void Dictionary::methods_do(void f(methodOop)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
387 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
388 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 klassOop k = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
390 if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // only take klass is we have the entry with the defining class loader
a61af66fc99e Initial load
duke
parents:
diff changeset
392 instanceKlass::cast(k)->methods_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 klassOop Dictionary::try_get_next_class() {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 if (_current_class_entry != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 klassOop k = _current_class_entry->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
403 _current_class_entry = _current_class_entry->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
404 return k;
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406 _current_class_index = (_current_class_index + 1) % table_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
407 _current_class_entry = bucket(_current_class_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409 // never reached
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 // Add a loaded class to the system dictionary.
a61af66fc99e Initial load
duke
parents:
diff changeset
414 // Readers of the SystemDictionary aren't always locked, so _buckets
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // is volatile. The store of the next field in the constructor is
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // also cast to volatile; we do this to ensure store order is maintained
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // by the compilers.
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 void Dictionary::add_klass(symbolHandle class_name, Handle class_loader,
a61af66fc99e Initial load
duke
parents:
diff changeset
420 KlassHandle obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 assert_locked_or_safepoint(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
422 assert(obj() != NULL, "adding NULL obj");
a61af66fc99e Initial load
duke
parents:
diff changeset
423 assert(Klass::cast(obj())->name() == class_name(), "sanity check on name");
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 unsigned int hash = compute_hash(class_name, class_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 int index = hash_to_index(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 DictionaryEntry* entry = new_entry(hash, obj(), class_loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
428 add_entry(index, entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // This routine does not lock the system dictionary.
a61af66fc99e Initial load
duke
parents:
diff changeset
433 //
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // Since readers don't hold a lock, we must make sure that system
a61af66fc99e Initial load
duke
parents:
diff changeset
435 // dictionary entries are only removed at a safepoint (when only one
a61af66fc99e Initial load
duke
parents:
diff changeset
436 // thread is running), and are added to in a safe way (all links must
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // be updated in an MT-safe manner).
a61af66fc99e Initial load
duke
parents:
diff changeset
438 //
a61af66fc99e Initial load
duke
parents:
diff changeset
439 // Callers should be aware that an entry could be added just after
a61af66fc99e Initial load
duke
parents:
diff changeset
440 // _buckets[index] is read here, so the caller will not see the new entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
441 DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
442 symbolHandle class_name,
a61af66fc99e Initial load
duke
parents:
diff changeset
443 Handle class_loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 symbolOop name_ = class_name();
a61af66fc99e Initial load
duke
parents:
diff changeset
445 oop loader_ = class_loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
446 debug_only(_lookup_count++);
a61af66fc99e Initial load
duke
parents:
diff changeset
447 for (DictionaryEntry* entry = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 entry != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 entry = entry->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 if (entry->hash() == hash && entry->equals(name_, loader_)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 return entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453 debug_only(_lookup_length++);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 klassOop Dictionary::find(int index, unsigned int hash, symbolHandle name,
a61af66fc99e Initial load
duke
parents:
diff changeset
460 Handle loader, Handle protection_domain, TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
461 DictionaryEntry* entry = get_entry(index, hash, name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 return entry->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
464 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
468
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 klassOop Dictionary::find_class(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
471 symbolHandle name, Handle loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 assert_locked_or_safepoint(SystemDictionary_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 assert (index == index_for(name, loader), "incorrect index?");
a61af66fc99e Initial load
duke
parents:
diff changeset
474
a61af66fc99e Initial load
duke
parents:
diff changeset
475 DictionaryEntry* entry = get_entry(index, hash, name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 return (entry != NULL) ? entry->klass() : (klassOop)NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 // Variant of find_class for shared classes. No locking required, as
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // that table is static.
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 klassOop Dictionary::find_shared_class(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
484 symbolHandle name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 assert (index == index_for(name, Handle()), "incorrect index?");
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 DictionaryEntry* entry = get_entry(index, hash, name, Handle());
a61af66fc99e Initial load
duke
parents:
diff changeset
488 return (entry != NULL) ? entry->klass() : (klassOop)NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 void Dictionary::add_protection_domain(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
493 instanceKlassHandle klass,
a61af66fc99e Initial load
duke
parents:
diff changeset
494 Handle loader, Handle protection_domain,
a61af66fc99e Initial load
duke
parents:
diff changeset
495 TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 symbolHandle klass_name(THREAD, klass->name());
a61af66fc99e Initial load
duke
parents:
diff changeset
497 DictionaryEntry* entry = get_entry(index, hash, klass_name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 assert(entry != NULL,"entry must be present, we just created it");
a61af66fc99e Initial load
duke
parents:
diff changeset
500 assert(protection_domain() != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
501 "real protection domain should be present");
a61af66fc99e Initial load
duke
parents:
diff changeset
502
a61af66fc99e Initial load
duke
parents:
diff changeset
503 entry->add_protection_domain(protection_domain());
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 assert(entry->contains_protection_domain(protection_domain()),
a61af66fc99e Initial load
duke
parents:
diff changeset
506 "now protection domain should be present");
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509
a61af66fc99e Initial load
duke
parents:
diff changeset
510 bool Dictionary::is_valid_protection_domain(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
511 symbolHandle name,
a61af66fc99e Initial load
duke
parents:
diff changeset
512 Handle loader,
a61af66fc99e Initial load
duke
parents:
diff changeset
513 Handle protection_domain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 DictionaryEntry* entry = get_entry(index, hash, name, loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 return entry->is_valid_protection_domain(protection_domain);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518
a61af66fc99e Initial load
duke
parents:
diff changeset
519 void Dictionary::reorder_dictionary() {
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 // Copy all the dictionary entries into a single master list.
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 DictionaryEntry* master_list = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
524 for (int i = 0; i < table_size(); ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 DictionaryEntry* p = bucket(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
526 while (p != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 DictionaryEntry* tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
528 tmp = p->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
529 p->set_next(master_list);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 master_list = p;
a61af66fc99e Initial load
duke
parents:
diff changeset
531 p = tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533 set_entry(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // Add the dictionary entries back to the list in the correct buckets.
a61af66fc99e Initial load
duke
parents:
diff changeset
537 Thread *thread = Thread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
538
a61af66fc99e Initial load
duke
parents:
diff changeset
539 while (master_list != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 DictionaryEntry* p = master_list;
a61af66fc99e Initial load
duke
parents:
diff changeset
541 master_list = master_list->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
542 p->set_next(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 symbolHandle class_name (thread, instanceKlass::cast((klassOop)(p->klass()))->name());
a61af66fc99e Initial load
duke
parents:
diff changeset
544 unsigned int hash = compute_hash(class_name, Handle(thread, p->loader()));
a61af66fc99e Initial load
duke
parents:
diff changeset
545 int index = hash_to_index(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
546 p->set_hash(hash);
a61af66fc99e Initial load
duke
parents:
diff changeset
547 p->set_next(bucket(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
548 set_entry(index, p);
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // ----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
554 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 void Dictionary::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
557 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
558 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 tty->print_cr("Java system dictionary (classes=%d)", number_of_entries());
a61af66fc99e Initial load
duke
parents:
diff changeset
561 tty->print_cr("^ indicates that initiating loader is different from "
a61af66fc99e Initial load
duke
parents:
diff changeset
562 "defining loader");
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
566 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
567 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 if (Verbose) tty->print("%4d: ", index);
a61af66fc99e Initial load
duke
parents:
diff changeset
569 klassOop e = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
570 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
571 bool is_defining_class =
a61af66fc99e Initial load
duke
parents:
diff changeset
572 (class_loader == instanceKlass::cast(e)->class_loader());
a61af66fc99e Initial load
duke
parents:
diff changeset
573 tty->print("%s%s", is_defining_class ? " " : "^",
a61af66fc99e Initial load
duke
parents:
diff changeset
574 Klass::cast(e)->external_name());
a61af66fc99e Initial load
duke
parents:
diff changeset
575 if (class_loader != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
576 tty->print(", loader ");
a61af66fc99e Initial load
duke
parents:
diff changeset
577 class_loader->print_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
578 }
a61af66fc99e Initial load
duke
parents:
diff changeset
579 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
580 }
a61af66fc99e Initial load
duke
parents:
diff changeset
581 }
a61af66fc99e Initial load
duke
parents:
diff changeset
582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
583
a61af66fc99e Initial load
duke
parents:
diff changeset
584 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
585
a61af66fc99e Initial load
duke
parents:
diff changeset
586 void Dictionary::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
587 guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
588 int element_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
589 for (int index = 0; index < table_size(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
590 for (DictionaryEntry* probe = bucket(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 probe != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
592 probe = probe->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 klassOop e = probe->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
594 oop class_loader = probe->loader();
a61af66fc99e Initial load
duke
parents:
diff changeset
595 guarantee(Klass::cast(e)->oop_is_instance(),
a61af66fc99e Initial load
duke
parents:
diff changeset
596 "Verify of system dictionary failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
597 // class loader must be present; a null class loader is the
a61af66fc99e Initial load
duke
parents:
diff changeset
598 // boostrap loader
a61af66fc99e Initial load
duke
parents:
diff changeset
599 guarantee(class_loader == NULL || class_loader->is_instance(),
a61af66fc99e Initial load
duke
parents:
diff changeset
600 "checking type of class_loader");
a61af66fc99e Initial load
duke
parents:
diff changeset
601 e->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
602 probe->verify_protection_domain_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
603 element_count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606 guarantee(number_of_entries() == element_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
607 "Verify of system dictionary failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
608 debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
a61af66fc99e Initial load
duke
parents:
diff changeset
609 }