annotate src/share/vm/classfile/dictionary.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children e5b0439ef4ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
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 class DictionaryEntry;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // The data structure for the system dictionary (and the shared system
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // dictionary).
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 class Dictionary : public TwoOopHashtable {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // current iteration index.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 static int _current_class_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // pointer to the current hash table entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
37 static DictionaryEntry* _current_class_entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 DictionaryEntry* get_entry(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 symbolHandle name, Handle loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 DictionaryEntry* bucket(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 return (DictionaryEntry*)Hashtable::bucket(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // The following method is not MT-safe and must be done under lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 DictionaryEntry** bucket_addr(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return (DictionaryEntry**)Hashtable::bucket_addr(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 void add_entry(int index, DictionaryEntry* new_entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Hashtable::add_entry(index, (HashtableEntry*)new_entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 Dictionary(int table_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 Dictionary(int table_size, HashtableBucket* t, int number_of_entries);
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 DictionaryEntry* new_entry(unsigned int hash, klassOop klass, oop loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 DictionaryEntry* new_entry();
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 void free_entry(DictionaryEntry* entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void add_klass(symbolHandle class_name, Handle class_loader,KlassHandle obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 klassOop find_class(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
69 symbolHandle name, Handle loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 klassOop find_shared_class(int index, unsigned int hash, symbolHandle name);
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // Compiler support
a61af66fc99e Initial load
duke
parents:
diff changeset
74 klassOop try_get_next_class();
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 void oops_do(OopClosure* f);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 void always_strong_classes_do(OopClosure* blk);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void classes_do(void f(klassOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
81 void classes_do(void f(klassOop, TRAPS), TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 void classes_do(void f(klassOop, oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void methods_do(void f(methodOop));
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Classes loaded by the bootstrap loader are always strongly reachable.
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // If we're not doing class unloading, all classes are strongly reachable.
a61af66fc99e Initial load
duke
parents:
diff changeset
90 static bool is_strongly_reachable(oop class_loader, oop klass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 assert (klass != NULL, "should have non-null klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return (class_loader == NULL || !ClassUnloading);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Unload (that is, break root links to) all unmarked classes and
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // loaders. Returns "true" iff something was unloaded.
a61af66fc99e Initial load
duke
parents:
diff changeset
97 bool do_unloading(BoolObjectClosure* is_alive);
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Protection domains
a61af66fc99e Initial load
duke
parents:
diff changeset
100 klassOop find(int index, unsigned int hash, symbolHandle name,
a61af66fc99e Initial load
duke
parents:
diff changeset
101 Handle loader, Handle protection_domain, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 bool is_valid_protection_domain(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
103 symbolHandle name, Handle class_loader,
a61af66fc99e Initial load
duke
parents:
diff changeset
104 Handle protection_domain);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 void add_protection_domain(int index, unsigned int hash,
a61af66fc99e Initial load
duke
parents:
diff changeset
106 instanceKlassHandle klass, Handle loader,
a61af66fc99e Initial load
duke
parents:
diff changeset
107 Handle protection_domain, TRAPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Sharing support
a61af66fc99e Initial load
duke
parents:
diff changeset
110 void dump(SerializeOopClosure* soc);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void restore(SerializeOopClosure* soc);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void reorder_dictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void print();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 };
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // The following classes can be in dictionary.cpp, but we need these
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // to be in header file so that SA's vmStructs can access.
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 class ProtectionDomainEntry :public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
127 ProtectionDomainEntry* _next;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 oop _protection_domain;
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ProtectionDomainEntry(oop protection_domain, ProtectionDomainEntry* next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _protection_domain = protection_domain;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _next = next;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 ProtectionDomainEntry* next() { return _next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 oop protection_domain() { return _protection_domain; }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 };
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // An entry in the system dictionary, this describes a class as
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // { klassOop, loader, protection_domain }.
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 class DictionaryEntry : public HashtableEntry {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // Contains the set of approved protection domains that can access
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // this system dictionary entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
147 ProtectionDomainEntry* _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 oop _loader;
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Tells whether a protection is in the approved set.
a61af66fc99e Initial load
duke
parents:
diff changeset
153 bool contains_protection_domain(oop protection_domain) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Adds a protection domain to the approved set.
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void add_protection_domain(oop protection_domain);
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 klassOop klass() const { return (klassOop)literal(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 klassOop* klass_addr() { return (klassOop*)literal_addr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 DictionaryEntry* next() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 return (DictionaryEntry*)HashtableEntry::next();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 DictionaryEntry** next_addr() {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return (DictionaryEntry**)HashtableEntry::next_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 oop loader() const { return _loader; }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 void set_loader(oop loader) { _loader = loader; }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 oop* loader_addr() { return &_loader; }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 ProtectionDomainEntry* pd_set() const { return _pd_set; }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 void set_pd_set(ProtectionDomainEntry* pd_set) { _pd_set = pd_set; }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 bool has_protection_domain() { return _pd_set != NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Tells whether the initiating class' protection can access the this _klass
a61af66fc99e Initial load
duke
parents:
diff changeset
178 bool is_valid_protection_domain(Handle protection_domain) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (!ProtectionDomainVerification) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 if (!SystemDictionary::has_checkPackageAccess()) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 return protection_domain() == NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
183 ? true
a61af66fc99e Initial load
duke
parents:
diff changeset
184 : contains_protection_domain(protection_domain());
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 void protection_domain_set_oops_do(OopClosure* f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 for (ProtectionDomainEntry* current = _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 current != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 current = current->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 f->do_oop(&(current->_protection_domain));
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 void verify_protection_domain_set() {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 for (ProtectionDomainEntry* current = _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
198 current != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 current = current->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 current->_protection_domain->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 bool equals(symbolOop class_name, oop class_loader) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 klassOop klass = (klassOop)literal();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 return (instanceKlass::cast(klass)->name() == class_name &&
a61af66fc99e Initial load
duke
parents:
diff changeset
207 _loader == class_loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 void print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 for (ProtectionDomainEntry* current = _pd_set;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 current != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 current = current->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 tty->print_cr("pd set = #%d", count);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 };