author | lfoltan |
Mon, 21 Oct 2019 13:13:16 -0400 | |
changeset 58722 | cba8afa5cfed |
parent 58542 | 94fe833a244b |
child 58679 | 9c3209ff7550 |
child 59070 | 22ee476cc664 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
48138 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/classFileStream.hpp" |
|
27 |
#include "classfile/classListParser.hpp" |
|
28 |
#include "classfile/classLoader.hpp" |
|
29 |
#include "classfile/classLoaderData.inline.hpp" |
|
52468
e0fd97beab7e
8213250: CDS archive creation aborts due to metaspace object allocation failure
iklam
parents:
51823
diff
changeset
|
30 |
#include "classfile/classLoaderDataGraph.hpp" |
48138 | 31 |
#include "classfile/classLoaderExt.hpp" |
32 |
#include "classfile/dictionary.hpp" |
|
33 |
#include "classfile/javaClasses.hpp" |
|
34 |
#include "classfile/symbolTable.hpp" |
|
35 |
#include "classfile/systemDictionary.hpp" |
|
36 |
#include "classfile/systemDictionaryShared.hpp" |
|
37 |
#include "classfile/verificationType.hpp" |
|
38 |
#include "classfile/vmSymbols.hpp" |
|
39 |
#include "logging/log.hpp" |
|
40 |
#include "memory/allocation.hpp" |
|
41 |
#include "memory/filemap.hpp" |
|
42 |
#include "memory/metadataFactory.hpp" |
|
43 |
#include "memory/metaspaceClosure.hpp" |
|
44 |
#include "memory/oopFactory.hpp" |
|
45 |
#include "memory/resourceArea.hpp" |
|
54786 | 46 |
#include "memory/universe.hpp" |
54927 | 47 |
#include "memory/dynamicArchive.hpp" |
48138 | 48 |
#include "oops/instanceKlass.hpp" |
49 |
#include "oops/klass.inline.hpp" |
|
50 |
#include "oops/objArrayOop.inline.hpp" |
|
51 |
#include "oops/oop.inline.hpp" |
|
49041
44122f767467
8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents:
48138
diff
changeset
|
52 |
#include "oops/typeArrayOop.inline.hpp" |
49393 | 53 |
#include "runtime/handles.inline.hpp" |
48138 | 54 |
#include "runtime/java.hpp" |
55 |
#include "runtime/javaCalls.hpp" |
|
56 |
#include "runtime/mutexLocker.hpp" |
|
57 |
#include "utilities/hashtable.inline.hpp" |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
58 |
#include "utilities/resourceHash.hpp" |
48138 | 59 |
#include "utilities/stringUtils.hpp" |
60 |
||
61 |
||
62 |
objArrayOop SystemDictionaryShared::_shared_protection_domains = NULL; |
|
63 |
objArrayOop SystemDictionaryShared::_shared_jar_urls = NULL; |
|
64 |
objArrayOop SystemDictionaryShared::_shared_jar_manifests = NULL; |
|
54927 | 65 |
DEBUG_ONLY(bool SystemDictionaryShared::_no_class_loading_should_happen = false;) |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
66 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
67 |
class DumpTimeSharedClassInfo: public CHeapObj<mtClass> { |
54927 | 68 |
bool _excluded; |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
69 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
70 |
struct DTConstraint { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
71 |
Symbol* _name; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
72 |
Symbol* _from_name; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
73 |
DTConstraint() : _name(NULL), _from_name(NULL) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
74 |
DTConstraint(Symbol* n, Symbol* fn) : _name(n), _from_name(fn) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
75 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
76 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
77 |
InstanceKlass* _klass; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
78 |
int _id; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
79 |
int _clsfile_size; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
80 |
int _clsfile_crc32; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
81 |
GrowableArray<DTConstraint>* _verifier_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
82 |
GrowableArray<char>* _verifier_constraint_flags; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
83 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
84 |
DumpTimeSharedClassInfo() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
85 |
_klass = NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
86 |
_id = -1; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
87 |
_clsfile_size = -1; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
88 |
_clsfile_crc32 = -1; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
89 |
_excluded = false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
90 |
_verifier_constraints = NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
91 |
_verifier_constraint_flags = NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
92 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
93 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
94 |
void add_verification_constraint(InstanceKlass* k, Symbol* name, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
95 |
Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
96 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
97 |
bool is_builtin() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
98 |
return SystemDictionaryShared::is_builtin(_klass); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
99 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
100 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
101 |
int num_constraints() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
102 |
if (_verifier_constraint_flags != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
103 |
return _verifier_constraint_flags->length(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
104 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
105 |
return 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
106 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
107 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
108 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
109 |
void metaspace_pointers_do(MetaspaceClosure* it) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
110 |
it->push(&_klass); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
111 |
if (_verifier_constraints != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
112 |
for (int i = 0; i < _verifier_constraints->length(); i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
113 |
DTConstraint* cons = _verifier_constraints->adr_at(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
114 |
it->push(&cons->_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
115 |
it->push(&cons->_from_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
116 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
117 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
118 |
} |
54927 | 119 |
|
120 |
void set_excluded() { |
|
121 |
_excluded = true; |
|
122 |
} |
|
123 |
||
124 |
bool is_excluded() { |
|
125 |
// _klass may become NULL due to DynamicArchiveBuilder::set_to_null |
|
126 |
return _excluded || _klass == NULL; |
|
127 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
128 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
129 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
130 |
class DumpTimeSharedClassTable: public ResourceHashtable< |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
131 |
InstanceKlass*, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
132 |
DumpTimeSharedClassInfo, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
133 |
primitive_hash<InstanceKlass*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
134 |
primitive_equals<InstanceKlass*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
135 |
15889, // prime number |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
136 |
ResourceObj::C_HEAP> |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
137 |
{ |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
138 |
int _builtin_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
139 |
int _unregistered_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
140 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
141 |
DumpTimeSharedClassInfo* find_or_allocate_info_for(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
142 |
DumpTimeSharedClassInfo* p = get(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
143 |
if (p == NULL) { |
54927 | 144 |
assert(!SystemDictionaryShared::no_class_loading_should_happen(), |
145 |
"no new classes can be loaded while dumping archive"); |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
146 |
put(k, DumpTimeSharedClassInfo()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
147 |
p = get(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
148 |
assert(p != NULL, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
149 |
p->_klass = k; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
150 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
151 |
return p; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
152 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
153 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
154 |
class CountClassByCategory : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
155 |
DumpTimeSharedClassTable* _table; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
156 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
157 |
CountClassByCategory(DumpTimeSharedClassTable* table) : _table(table) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
158 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
54927 | 159 |
if (!info.is_excluded()) { |
160 |
if (info.is_builtin()) { |
|
161 |
++ _table->_builtin_count; |
|
162 |
} else { |
|
163 |
++ _table->_unregistered_count; |
|
164 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
165 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
166 |
return true; // keep on iterating |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
167 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
168 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
169 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
170 |
void update_counts() { |
54927 | 171 |
_builtin_count = 0; |
172 |
_unregistered_count = 0; |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
173 |
CountClassByCategory counter(this); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
174 |
iterate(&counter); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
175 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
176 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
177 |
int count_of(bool is_builtin) const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
178 |
if (is_builtin) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
179 |
return _builtin_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
180 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
181 |
return _unregistered_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
182 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
183 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
184 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
185 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
186 |
class RunTimeSharedClassInfo { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
187 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
188 |
struct CrcInfo { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
189 |
int _clsfile_size; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
190 |
int _clsfile_crc32; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
191 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
192 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
193 |
// This is different than DumpTimeSharedClassInfo::DTConstraint. We use |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
194 |
// u4 instead of Symbol* to save space on 64-bit CPU. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
195 |
struct RTConstraint { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
196 |
u4 _name; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
197 |
u4 _from_name; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
198 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
199 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
200 |
InstanceKlass* _klass; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
201 |
int _num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
202 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
203 |
// optional CrcInfo _crc; (only for UNREGISTERED classes) |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
204 |
// optional RTConstraint _verifier_constraints[_num_constraints] |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
205 |
// optional char _verifier_constraint_flags[_num_constraints] |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
206 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
207 |
private: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
208 |
static size_t header_size_size() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
209 |
return sizeof(RunTimeSharedClassInfo); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
210 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
211 |
static size_t crc_size(InstanceKlass* klass) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
212 |
if (!SystemDictionaryShared::is_builtin(klass)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
213 |
return sizeof(CrcInfo); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
214 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
215 |
return 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
216 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
217 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
218 |
static size_t verifier_constraints_size(int num_constraints) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
219 |
return sizeof(RTConstraint) * num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
220 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
221 |
static size_t verifier_constraint_flags_size(int num_constraints) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
222 |
return sizeof(char) * num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
223 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
224 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
225 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
226 |
static size_t byte_size(InstanceKlass* klass, int num_constraints) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
227 |
return header_size_size() + |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
228 |
crc_size(klass) + |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
229 |
verifier_constraints_size(num_constraints) + |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
230 |
verifier_constraint_flags_size(num_constraints); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
231 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
232 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
233 |
private: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
234 |
size_t crc_offset() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
235 |
return header_size_size(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
236 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
237 |
size_t verifier_constraints_offset() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
238 |
return crc_offset() + crc_size(_klass); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
239 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
240 |
size_t verifier_constraint_flags_offset() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
241 |
return verifier_constraints_offset() + verifier_constraints_size(_num_constraints); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
242 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
243 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
244 |
void check_constraint_offset(int i) const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
245 |
assert(0 <= i && i < _num_constraints, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
246 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
247 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
248 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
249 |
CrcInfo* crc() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
250 |
assert(crc_size(_klass) > 0, "must be"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
251 |
return (CrcInfo*)(address(this) + crc_offset()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
252 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
253 |
RTConstraint* verifier_constraints() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
254 |
assert(_num_constraints > 0, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
255 |
return (RTConstraint*)(address(this) + verifier_constraints_offset()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
256 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
257 |
RTConstraint* verifier_constraint_at(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
258 |
check_constraint_offset(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
259 |
return verifier_constraints() + i; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
260 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
261 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
262 |
char* verifier_constraint_flags() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
263 |
assert(_num_constraints > 0, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
264 |
return (char*)(address(this) + verifier_constraint_flags_offset()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
265 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
266 |
|
54927 | 267 |
static u4 object_delta_u4(Symbol* sym) { |
268 |
if (DynamicDumpSharedSpaces) { |
|
269 |
sym = DynamicArchive::original_to_target(sym); |
|
270 |
} |
|
271 |
return MetaspaceShared::object_delta_u4(sym); |
|
272 |
} |
|
273 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
274 |
void init(DumpTimeSharedClassInfo& info) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
275 |
_klass = info._klass; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
276 |
if (!SystemDictionaryShared::is_builtin(_klass)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
277 |
CrcInfo* c = crc(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
278 |
c->_clsfile_size = info._clsfile_size; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
279 |
c->_clsfile_crc32 = info._clsfile_crc32; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
280 |
} |
54927 | 281 |
_num_constraints = info.num_constraints(); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
282 |
if (_num_constraints > 0) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
283 |
RTConstraint* constraints = verifier_constraints(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
284 |
char* flags = verifier_constraint_flags(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
285 |
int i; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
286 |
for (i = 0; i < _num_constraints; i++) { |
54927 | 287 |
constraints[i]._name = object_delta_u4(info._verifier_constraints->at(i)._name); |
288 |
constraints[i]._from_name = object_delta_u4(info._verifier_constraints->at(i)._from_name); |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
289 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
290 |
for (i = 0; i < _num_constraints; i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
291 |
flags[i] = info._verifier_constraint_flags->at(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
292 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
293 |
} |
54927 | 294 |
if (DynamicDumpSharedSpaces) { |
295 |
_klass = DynamicArchive::original_to_target(info._klass); |
|
296 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
297 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
298 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
299 |
bool matches(int clsfile_size, int clsfile_crc32) const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
300 |
return crc()->_clsfile_size == clsfile_size && |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
301 |
crc()->_clsfile_crc32 == clsfile_crc32; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
302 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
303 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
304 |
Symbol* get_constraint_name(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
305 |
return (Symbol*)(SharedBaseAddress + verifier_constraint_at(i)->_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
306 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
307 |
Symbol* get_constraint_from_name(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
308 |
return (Symbol*)(SharedBaseAddress + verifier_constraint_at(i)->_from_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
309 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
310 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
311 |
char get_constraint_flag(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
312 |
check_constraint_offset(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
313 |
return verifier_constraint_flags()[i]; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
314 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
315 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
316 |
private: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
317 |
// ArchiveCompactor::allocate() has reserved a pointer immediately before |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
318 |
// archived InstanceKlasses. We can use this slot to do a quick |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
319 |
// lookup of InstanceKlass* -> RunTimeSharedClassInfo* without |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
320 |
// building a new hashtable. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
321 |
// |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
322 |
// info_pointer_addr(klass) --> 0x0100 RunTimeSharedClassInfo* |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
323 |
// InstanceKlass* klass --> 0x0108 <C++ vtbl> |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
324 |
// 0x0110 fields from Klass ... |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
325 |
static RunTimeSharedClassInfo** info_pointer_addr(InstanceKlass* klass) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
326 |
return &((RunTimeSharedClassInfo**)klass)[-1]; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
327 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
328 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
329 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
330 |
static RunTimeSharedClassInfo* get_for(InstanceKlass* klass) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
331 |
return *info_pointer_addr(klass); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
332 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
333 |
static void set_for(InstanceKlass* klass, RunTimeSharedClassInfo* record) { |
54927 | 334 |
if (DynamicDumpSharedSpaces) { |
335 |
klass = DynamicArchive::original_to_buffer(klass); |
|
336 |
*info_pointer_addr(klass) = DynamicArchive::buffer_to_target(record); |
|
337 |
} else { |
|
338 |
*info_pointer_addr(klass) = record; |
|
339 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
340 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
341 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
342 |
// Used by RunTimeSharedDictionary to implement OffsetCompactHashtable::EQUALS |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
343 |
static inline bool EQUALS( |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
344 |
const RunTimeSharedClassInfo* value, Symbol* key, int len_unused) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
345 |
return (value->_klass->name() == key); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
346 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
347 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
348 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
349 |
class RunTimeSharedDictionary : public OffsetCompactHashtable< |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
350 |
Symbol*, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
351 |
const RunTimeSharedClassInfo*, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
352 |
RunTimeSharedClassInfo::EQUALS> {}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
353 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
354 |
static DumpTimeSharedClassTable* _dumptime_table = NULL; |
54927 | 355 |
// SystemDictionaries in the base layer static archive |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
356 |
static RunTimeSharedDictionary _builtin_dictionary; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
357 |
static RunTimeSharedDictionary _unregistered_dictionary; |
54927 | 358 |
// SystemDictionaries in the top layer dynamic archive |
359 |
static RunTimeSharedDictionary _dynamic_builtin_dictionary; |
|
360 |
static RunTimeSharedDictionary _dynamic_unregistered_dictionary; |
|
48138 | 361 |
|
362 |
oop SystemDictionaryShared::shared_protection_domain(int index) { |
|
363 |
return _shared_protection_domains->obj_at(index); |
|
364 |
} |
|
365 |
||
366 |
oop SystemDictionaryShared::shared_jar_url(int index) { |
|
367 |
return _shared_jar_urls->obj_at(index); |
|
368 |
} |
|
369 |
||
370 |
oop SystemDictionaryShared::shared_jar_manifest(int index) { |
|
371 |
return _shared_jar_manifests->obj_at(index); |
|
372 |
} |
|
373 |
||
374 |
||
375 |
Handle SystemDictionaryShared::get_shared_jar_manifest(int shared_path_index, TRAPS) { |
|
376 |
Handle manifest ; |
|
377 |
if (shared_jar_manifest(shared_path_index) == NULL) { |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
378 |
SharedClassPathEntry* ent = FileMapInfo::shared_path(shared_path_index); |
48138 | 379 |
long size = ent->manifest_size(); |
380 |
if (size <= 0) { |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
381 |
return Handle(); |
48138 | 382 |
} |
383 |
||
384 |
// ByteArrayInputStream bais = new ByteArrayInputStream(buf); |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
385 |
const char* src = ent->manifest(); |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
386 |
assert(src != NULL, "No Manifest data"); |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
387 |
typeArrayOop buf = oopFactory::new_byteArray(size, CHECK_NH); |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
388 |
typeArrayHandle bufhandle(THREAD, buf); |
50389
7e8c0409a747
8198285: More consistent Access API for arraycopy
rkennke
parents:
50152
diff
changeset
|
389 |
ArrayAccess<>::arraycopy_from_native(reinterpret_cast<const jbyte*>(src), |
7e8c0409a747
8198285: More consistent Access API for arraycopy
rkennke
parents:
50152
diff
changeset
|
390 |
buf, typeArrayOopDesc::element_offset<jbyte>(0), size); |
48138 | 391 |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
392 |
Handle bais = JavaCalls::construct_new_instance(SystemDictionary::ByteArrayInputStream_klass(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
393 |
vmSymbols::byte_array_void_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
394 |
bufhandle, CHECK_NH); |
48138 | 395 |
|
396 |
// manifest = new Manifest(bais) |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
397 |
manifest = JavaCalls::construct_new_instance(SystemDictionary::Jar_Manifest_klass(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
398 |
vmSymbols::input_stream_void_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
399 |
bais, CHECK_NH); |
48138 | 400 |
atomic_set_shared_jar_manifest(shared_path_index, manifest()); |
401 |
} |
|
402 |
||
403 |
manifest = Handle(THREAD, shared_jar_manifest(shared_path_index)); |
|
404 |
assert(manifest.not_null(), "sanity"); |
|
405 |
return manifest; |
|
406 |
} |
|
407 |
||
408 |
Handle SystemDictionaryShared::get_shared_jar_url(int shared_path_index, TRAPS) { |
|
409 |
Handle url_h; |
|
410 |
if (shared_jar_url(shared_path_index) == NULL) { |
|
411 |
JavaValue result(T_OBJECT); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
412 |
const char* path = FileMapInfo::shared_path_name(shared_path_index); |
48138 | 413 |
Handle path_string = java_lang_String::create_from_str(path, CHECK_(url_h)); |
414 |
Klass* classLoaders_klass = |
|
415 |
SystemDictionary::jdk_internal_loader_ClassLoaders_klass(); |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
416 |
JavaCalls::call_static(&result, classLoaders_klass, |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
417 |
vmSymbols::toFileURL_name(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
418 |
vmSymbols::toFileURL_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
419 |
path_string, CHECK_(url_h)); |
48138 | 420 |
|
421 |
atomic_set_shared_jar_url(shared_path_index, (oop)result.get_jobject()); |
|
422 |
} |
|
423 |
||
424 |
url_h = Handle(THREAD, shared_jar_url(shared_path_index)); |
|
425 |
assert(url_h.not_null(), "sanity"); |
|
426 |
return url_h; |
|
427 |
} |
|
428 |
||
429 |
Handle SystemDictionaryShared::get_package_name(Symbol* class_name, TRAPS) { |
|
430 |
ResourceMark rm(THREAD); |
|
431 |
Handle pkgname_string; |
|
432 |
char* pkgname = (char*) ClassLoader::package_from_name((const char*) class_name->as_C_string()); |
|
433 |
if (pkgname != NULL) { // Package prefix found |
|
434 |
StringUtils::replace_no_expand(pkgname, "/", "."); |
|
435 |
pkgname_string = java_lang_String::create_from_str(pkgname, |
|
436 |
CHECK_(pkgname_string)); |
|
437 |
} |
|
438 |
return pkgname_string; |
|
439 |
} |
|
440 |
||
441 |
// Define Package for shared app classes from JAR file and also checks for |
|
442 |
// package sealing (all done in Java code) |
|
443 |
// See http://docs.oracle.com/javase/tutorial/deployment/jar/sealman.html |
|
444 |
void SystemDictionaryShared::define_shared_package(Symbol* class_name, |
|
445 |
Handle class_loader, |
|
446 |
Handle manifest, |
|
447 |
Handle url, |
|
448 |
TRAPS) { |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
449 |
assert(SystemDictionary::is_system_class_loader(class_loader()), "unexpected class loader"); |
48138 | 450 |
// get_package_name() returns a NULL handle if the class is in unnamed package |
451 |
Handle pkgname_string = get_package_name(class_name, CHECK); |
|
452 |
if (pkgname_string.not_null()) { |
|
453 |
Klass* app_classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(); |
|
454 |
JavaValue result(T_OBJECT); |
|
455 |
JavaCallArguments args(3); |
|
456 |
args.set_receiver(class_loader); |
|
457 |
args.push_oop(pkgname_string); |
|
458 |
args.push_oop(manifest); |
|
459 |
args.push_oop(url); |
|
460 |
JavaCalls::call_virtual(&result, app_classLoader_klass, |
|
461 |
vmSymbols::defineOrCheckPackage_name(), |
|
462 |
vmSymbols::defineOrCheckPackage_signature(), |
|
463 |
&args, |
|
464 |
CHECK); |
|
465 |
} |
|
466 |
} |
|
467 |
||
468 |
// Define Package for shared app/platform classes from named module |
|
469 |
void SystemDictionaryShared::define_shared_package(Symbol* class_name, |
|
470 |
Handle class_loader, |
|
471 |
ModuleEntry* mod_entry, |
|
472 |
TRAPS) { |
|
473 |
assert(mod_entry != NULL, "module_entry should not be NULL"); |
|
474 |
Handle module_handle(THREAD, mod_entry->module()); |
|
475 |
||
476 |
Handle pkg_name = get_package_name(class_name, CHECK); |
|
477 |
assert(pkg_name.not_null(), "Package should not be null for class in named module"); |
|
478 |
||
479 |
Klass* classLoader_klass; |
|
480 |
if (SystemDictionary::is_system_class_loader(class_loader())) { |
|
481 |
classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(); |
|
482 |
} else { |
|
483 |
assert(SystemDictionary::is_platform_class_loader(class_loader()), "unexpected classloader"); |
|
484 |
classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass(); |
|
485 |
} |
|
486 |
||
487 |
JavaValue result(T_OBJECT); |
|
488 |
JavaCallArguments args(2); |
|
489 |
args.set_receiver(class_loader); |
|
490 |
args.push_oop(pkg_name); |
|
491 |
args.push_oop(module_handle); |
|
492 |
JavaCalls::call_virtual(&result, classLoader_klass, |
|
493 |
vmSymbols::definePackage_name(), |
|
494 |
vmSymbols::definePackage_signature(), |
|
495 |
&args, |
|
496 |
CHECK); |
|
497 |
} |
|
498 |
||
499 |
// Get the ProtectionDomain associated with the CodeSource from the classloader. |
|
500 |
Handle SystemDictionaryShared::get_protection_domain_from_classloader(Handle class_loader, |
|
501 |
Handle url, TRAPS) { |
|
502 |
// CodeSource cs = new CodeSource(url, null); |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
503 |
Handle cs = JavaCalls::construct_new_instance(SystemDictionary::CodeSource_klass(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
504 |
vmSymbols::url_code_signer_array_void_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
505 |
url, Handle(), CHECK_NH); |
48138 | 506 |
|
507 |
// protection_domain = SecureClassLoader.getProtectionDomain(cs); |
|
508 |
Klass* secureClassLoader_klass = SystemDictionary::SecureClassLoader_klass(); |
|
509 |
JavaValue obj_result(T_OBJECT); |
|
510 |
JavaCalls::call_virtual(&obj_result, class_loader, secureClassLoader_klass, |
|
511 |
vmSymbols::getProtectionDomain_name(), |
|
512 |
vmSymbols::getProtectionDomain_signature(), |
|
513 |
cs, CHECK_NH); |
|
514 |
return Handle(THREAD, (oop)obj_result.get_jobject()); |
|
515 |
} |
|
516 |
||
517 |
// Returns the ProtectionDomain associated with the JAR file identified by the url. |
|
518 |
Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader, |
|
519 |
int shared_path_index, |
|
520 |
Handle url, |
|
521 |
TRAPS) { |
|
522 |
Handle protection_domain; |
|
523 |
if (shared_protection_domain(shared_path_index) == NULL) { |
|
524 |
Handle pd = get_protection_domain_from_classloader(class_loader, url, THREAD); |
|
525 |
atomic_set_shared_protection_domain(shared_path_index, pd()); |
|
526 |
} |
|
527 |
||
528 |
// Acquire from the cache because if another thread beats the current one to |
|
529 |
// set the shared protection_domain and the atomic_set fails, the current thread |
|
530 |
// needs to get the updated protection_domain from the cache. |
|
531 |
protection_domain = Handle(THREAD, shared_protection_domain(shared_path_index)); |
|
532 |
assert(protection_domain.not_null(), "sanity"); |
|
533 |
return protection_domain; |
|
534 |
} |
|
535 |
||
536 |
// Returns the ProtectionDomain associated with the moduleEntry. |
|
537 |
Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader, |
|
538 |
ModuleEntry* mod, TRAPS) { |
|
539 |
ClassLoaderData *loader_data = mod->loader_data(); |
|
540 |
if (mod->shared_protection_domain() == NULL) { |
|
541 |
Symbol* location = mod->location(); |
|
542 |
if (location != NULL) { |
|
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
543 |
Handle location_string = java_lang_String::create_from_symbol( |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
544 |
location, CHECK_NH); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
545 |
Handle url; |
48138 | 546 |
JavaValue result(T_OBJECT); |
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
547 |
if (location->starts_with("jrt:/")) { |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
548 |
url = JavaCalls::construct_new_instance(SystemDictionary::URL_klass(), |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
549 |
vmSymbols::string_void_signature(), |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
550 |
location_string, CHECK_NH); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
551 |
} else { |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
552 |
Klass* classLoaders_klass = |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
553 |
SystemDictionary::jdk_internal_loader_ClassLoaders_klass(); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
554 |
JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(), |
48138 | 555 |
vmSymbols::toFileURL_signature(), |
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
556 |
location_string, CHECK_NH); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
557 |
url = Handle(THREAD, (oop)result.get_jobject()); |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
558 |
} |
48138 | 559 |
|
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
560 |
Handle pd = get_protection_domain_from_classloader(class_loader, url, |
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
561 |
CHECK_NH); |
48138 | 562 |
mod->set_shared_protection_domain(loader_data, pd); |
563 |
} |
|
564 |
} |
|
565 |
||
53249
fbab5d82f3d7
8214827: Incorrect call ClassLoaders.toFileURL("jrt:/java.compiler")
jiangli
parents:
52514
diff
changeset
|
566 |
Handle protection_domain(THREAD, mod->shared_protection_domain()); |
48138 | 567 |
assert(protection_domain.not_null(), "sanity"); |
568 |
return protection_domain; |
|
569 |
} |
|
570 |
||
571 |
// Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with |
|
572 |
// the given InstanceKlass. |
|
573 |
// Returns the ProtectionDomain for the InstanceKlass. |
|
574 |
Handle SystemDictionaryShared::init_security_info(Handle class_loader, InstanceKlass* ik, TRAPS) { |
|
575 |
Handle pd; |
|
576 |
||
577 |
if (ik != NULL) { |
|
578 |
int index = ik->shared_classpath_index(); |
|
579 |
assert(index >= 0, "Sanity"); |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
580 |
SharedClassPathEntry* ent = FileMapInfo::shared_path(index); |
48138 | 581 |
Symbol* class_name = ik->name(); |
582 |
||
583 |
if (ent->is_modules_image()) { |
|
584 |
// For shared app/platform classes originated from the run-time image: |
|
585 |
// The ProtectionDomains are cached in the corresponding ModuleEntries |
|
586 |
// for fast access by the VM. |
|
587 |
ResourceMark rm; |
|
588 |
ClassLoaderData *loader_data = |
|
589 |
ClassLoaderData::class_loader_data(class_loader()); |
|
590 |
PackageEntryTable* pkgEntryTable = loader_data->packages(); |
|
591 |
TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK_(pd)); |
|
592 |
if (pkg_name != NULL) { |
|
593 |
PackageEntry* pkg_entry = pkgEntryTable->lookup_only(pkg_name); |
|
594 |
if (pkg_entry != NULL) { |
|
595 |
ModuleEntry* mod_entry = pkg_entry->module(); |
|
596 |
pd = get_shared_protection_domain(class_loader, mod_entry, THREAD); |
|
597 |
define_shared_package(class_name, class_loader, mod_entry, CHECK_(pd)); |
|
598 |
} |
|
599 |
} |
|
600 |
} else { |
|
601 |
// For shared app/platform classes originated from JAR files on the class path: |
|
602 |
// Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length |
|
603 |
// as the shared classpath table in the shared archive (see |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
604 |
// FileMap::_shared_path_table in filemap.hpp for details). |
48138 | 605 |
// |
606 |
// If a shared InstanceKlass k is loaded from the class path, let |
|
607 |
// |
|
608 |
// index = k->shared_classpath_index(): |
|
609 |
// |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
610 |
// FileMap::_shared_path_table[index] identifies the JAR file that contains k. |
48138 | 611 |
// |
612 |
// k's protection domain is: |
|
613 |
// |
|
614 |
// ProtectionDomain pd = _shared_protection_domains[index]; |
|
615 |
// |
|
616 |
// and k's Package is initialized using |
|
617 |
// |
|
618 |
// manifest = _shared_jar_manifests[index]; |
|
619 |
// url = _shared_jar_urls[index]; |
|
620 |
// define_shared_package(class_name, class_loader, manifest, url, CHECK_(pd)); |
|
621 |
// |
|
622 |
// Note that if an element of these 3 _shared_xxx arrays is NULL, it will be initialized by |
|
623 |
// the corresponding SystemDictionaryShared::get_shared_xxx() function. |
|
624 |
Handle manifest = get_shared_jar_manifest(index, CHECK_(pd)); |
|
625 |
Handle url = get_shared_jar_url(index, CHECK_(pd)); |
|
626 |
define_shared_package(class_name, class_loader, manifest, url, CHECK_(pd)); |
|
627 |
pd = get_shared_protection_domain(class_loader, index, url, CHECK_(pd)); |
|
628 |
} |
|
629 |
} |
|
630 |
return pd; |
|
631 |
} |
|
632 |
||
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
633 |
bool SystemDictionaryShared::is_sharing_possible(ClassLoaderData* loader_data) { |
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
634 |
oop class_loader = loader_data->class_loader(); |
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
635 |
return (class_loader == NULL || |
49931 | 636 |
SystemDictionary::is_system_class_loader(class_loader) || |
637 |
SystemDictionary::is_platform_class_loader(class_loader)); |
|
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
638 |
} |
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
639 |
|
48138 | 640 |
// Currently AppCDS only archives classes from the run-time image, the |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
641 |
// -Xbootclasspath/a path, the class path, and the module path. |
48138 | 642 |
// |
643 |
// Check if a shared class can be loaded by the specific classloader. Following |
|
644 |
// are the "visible" archived classes for different classloaders. |
|
645 |
// |
|
646 |
// NULL classloader: |
|
647 |
// - see SystemDictionary::is_shared_class_visible() |
|
648 |
// Platform classloader: |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
649 |
// - Module class from runtime image. ModuleEntry must be defined in the |
48138 | 650 |
// classloader. |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
651 |
// App classloader: |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
652 |
// - Module Class from runtime image and module path. ModuleEntry must be defined in the |
48138 | 653 |
// classloader. |
654 |
// - Class from -cp. The class must have no PackageEntry defined in any of the |
|
655 |
// boot/platform/app classloader, or must be in the unnamed module defined in the |
|
656 |
// AppClassLoader. |
|
657 |
bool SystemDictionaryShared::is_shared_class_visible_for_classloader( |
|
658 |
InstanceKlass* ik, |
|
659 |
Handle class_loader, |
|
660 |
Symbol* pkg_name, |
|
661 |
PackageEntry* pkg_entry, |
|
662 |
ModuleEntry* mod_entry, |
|
663 |
TRAPS) { |
|
664 |
assert(class_loader.not_null(), "Class loader should not be NULL"); |
|
665 |
assert(Universe::is_module_initialized(), "Module system is not initialized"); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
666 |
ResourceMark rm(THREAD); |
48138 | 667 |
|
668 |
int path_index = ik->shared_classpath_index(); |
|
669 |
SharedClassPathEntry* ent = |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
670 |
(SharedClassPathEntry*)FileMapInfo::shared_path(path_index); |
48138 | 671 |
|
672 |
if (SystemDictionary::is_platform_class_loader(class_loader())) { |
|
673 |
assert(ent != NULL, "shared class for PlatformClassLoader should have valid SharedClassPathEntry"); |
|
674 |
// The PlatformClassLoader can only load archived class originated from the |
|
675 |
// run-time image. The class' PackageEntry/ModuleEntry must be |
|
676 |
// defined by the PlatformClassLoader. |
|
677 |
if (mod_entry != NULL) { |
|
678 |
// PackageEntry/ModuleEntry is found in the classloader. Check if the |
|
679 |
// ModuleEntry's location agrees with the archived class' origination. |
|
680 |
if (ent->is_modules_image() && mod_entry->location()->starts_with("jrt:")) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
681 |
return true; // Module class from the runtime image |
48138 | 682 |
} |
683 |
} |
|
684 |
} else if (SystemDictionary::is_system_class_loader(class_loader())) { |
|
685 |
assert(ent != NULL, "shared class for system loader should have valid SharedClassPathEntry"); |
|
58499
d62c7224d5b7
8231993: Remove redundant pkg_str param from is_shared_class_visible_for_classloader
redestad
parents:
58447
diff
changeset
|
686 |
if (pkg_name == NULL) { |
48138 | 687 |
// The archived class is in the unnamed package. Currently, the boot image |
688 |
// does not contain any class in the unnamed package. |
|
689 |
assert(!ent->is_modules_image(), "Class in the unnamed package must be from the classpath"); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
690 |
if (path_index >= ClassLoaderExt::app_class_paths_start_index()) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
691 |
assert(path_index < ClassLoaderExt::app_module_paths_start_index(), "invalid path_index"); |
48138 | 692 |
return true; |
693 |
} |
|
694 |
} else { |
|
695 |
// Check if this is from a PackageEntry/ModuleEntry defined in the AppClassloader. |
|
696 |
if (pkg_entry == NULL) { |
|
697 |
// It's not guaranteed that the class is from the classpath if the |
|
698 |
// PackageEntry cannot be found from the AppClassloader. Need to check |
|
699 |
// the boot and platform classloader as well. |
|
700 |
if (get_package_entry(pkg_name, ClassLoaderData::class_loader_data_or_null(SystemDictionary::java_platform_loader())) == NULL && |
|
701 |
get_package_entry(pkg_name, ClassLoaderData::the_null_class_loader_data()) == NULL) { |
|
702 |
// The PackageEntry is not defined in any of the boot/platform/app classloaders. |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
703 |
// The archived class must from -cp path and not from the runtime image. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
704 |
if (!ent->is_modules_image() && path_index >= ClassLoaderExt::app_class_paths_start_index() && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
705 |
path_index < ClassLoaderExt::app_module_paths_start_index()) { |
48138 | 706 |
return true; |
707 |
} |
|
708 |
} |
|
709 |
} else if (mod_entry != NULL) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
710 |
// The package/module is defined in the AppClassLoader. We support |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
711 |
// archiving application module class from the runtime image or from |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
712 |
// a named module from a module path. |
48138 | 713 |
// Packages from the -cp path are in the unnamed_module. |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
714 |
if (ent->is_modules_image() && mod_entry->location()->starts_with("jrt:")) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
715 |
// shared module class from runtime image |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
716 |
return true; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
717 |
} else if (pkg_entry->in_unnamed_module() && path_index >= ClassLoaderExt::app_class_paths_start_index() && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
718 |
path_index < ClassLoaderExt::app_module_paths_start_index()) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
719 |
// shared class from -cp |
48138 | 720 |
DEBUG_ONLY( \ |
721 |
ClassLoaderData* loader_data = class_loader_data(class_loader); \ |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
722 |
assert(mod_entry == loader_data->unnamed_module(), "the unnamed module is not defined in the classloader");) |
48138 | 723 |
return true; |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
724 |
} else { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
725 |
if(!pkg_entry->in_unnamed_module() && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
726 |
(path_index >= ClassLoaderExt::app_module_paths_start_index())&& |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
727 |
(path_index < FileMapInfo::get_number_of_shared_paths()) && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
728 |
(strcmp(ent->name(), ClassLoader::skip_uri_protocol(mod_entry->location()->as_C_string())) == 0)) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
729 |
// shared module class from module path |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
730 |
return true; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
731 |
} else { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
732 |
assert(path_index < FileMapInfo::get_number_of_shared_paths(), "invalid path_index"); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
733 |
} |
48138 | 734 |
} |
735 |
} |
|
736 |
} |
|
737 |
} else { |
|
738 |
// TEMP: if a shared class can be found by a custom loader, consider it visible now. |
|
739 |
// FIXME: is this actually correct? |
|
740 |
return true; |
|
741 |
} |
|
742 |
return false; |
|
743 |
} |
|
744 |
||
54927 | 745 |
bool SystemDictionaryShared::has_platform_or_app_classes() { |
58096 | 746 |
if (FileMapInfo::current_info()->has_platform_or_app_classes()) { |
54927 | 747 |
return true; |
748 |
} |
|
749 |
if (DynamicArchive::is_mapped() && |
|
58096 | 750 |
FileMapInfo::dynamic_info()->has_platform_or_app_classes()) { |
54927 | 751 |
return true; |
752 |
} |
|
753 |
return false; |
|
754 |
} |
|
755 |
||
48138 | 756 |
// The following stack shows how this code is reached: |
757 |
// |
|
758 |
// [0] SystemDictionaryShared::find_or_load_shared_class() |
|
759 |
// [1] JVM_FindLoadedClass |
|
760 |
// [2] java.lang.ClassLoader.findLoadedClass0() |
|
761 |
// [3] java.lang.ClassLoader.findLoadedClass() |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
762 |
// [4] jdk.internal.loader.BuiltinClassLoader.loadClassOrNull() |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
763 |
// [5] jdk.internal.loader.BuiltinClassLoader.loadClass() |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
764 |
// [6] jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(), or |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
765 |
// jdk.internal.loader.ClassLoaders$PlatformClassLoader.loadClass() |
48138 | 766 |
// |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
767 |
// AppCDS supports fast class loading for these 2 built-in class loaders: |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
768 |
// jdk.internal.loader.ClassLoaders$PlatformClassLoader |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
769 |
// jdk.internal.loader.ClassLoaders$AppClassLoader |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
770 |
// with the following assumptions (based on the JDK core library source code): |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
771 |
// |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
772 |
// [a] these two loaders use the BuiltinClassLoader.loadClassOrNull() to |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
773 |
// load the named class. |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
774 |
// [b] BuiltinClassLoader.loadClassOrNull() first calls findLoadedClass(name). |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
775 |
// [c] At this point, if we can find the named class inside the |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
776 |
// shared_dictionary, we can perform further checks (see |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
777 |
// is_shared_class_visible_for_classloader() to ensure that this class |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
778 |
// was loaded by the same class loader during dump time. |
48138 | 779 |
// |
780 |
// Given these assumptions, we intercept the findLoadedClass() call to invoke |
|
781 |
// SystemDictionaryShared::find_or_load_shared_class() to load the shared class from |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
782 |
// the archive for the 2 built-in class loaders. This way, |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
783 |
// we can improve start-up because we avoid decoding the classfile, |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
784 |
// and avoid delegating to the parent loader. |
48138 | 785 |
// |
786 |
// NOTE: there's a lot of assumption about the Java code. If any of that change, this |
|
787 |
// needs to be redesigned. |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
788 |
|
48138 | 789 |
InstanceKlass* SystemDictionaryShared::find_or_load_shared_class( |
790 |
Symbol* name, Handle class_loader, TRAPS) { |
|
791 |
InstanceKlass* k = NULL; |
|
49931 | 792 |
if (UseSharedSpaces) { |
54927 | 793 |
if (!has_platform_or_app_classes()) { |
49931 | 794 |
return NULL; |
48138 | 795 |
} |
796 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
797 |
if (SystemDictionary::is_system_class_loader(class_loader()) || |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
798 |
SystemDictionary::is_platform_class_loader(class_loader())) { |
49931 | 799 |
// Fix for 4474172; see evaluation for more details |
800 |
class_loader = Handle( |
|
801 |
THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
|
802 |
ClassLoaderData *loader_data = register_loader(class_loader); |
|
803 |
Dictionary* dictionary = loader_data->dictionary(); |
|
804 |
||
805 |
unsigned int d_hash = dictionary->compute_hash(name); |
|
806 |
||
807 |
bool DoObjectLock = true; |
|
808 |
if (is_parallelCapable(class_loader)) { |
|
809 |
DoObjectLock = false; |
|
810 |
} |
|
48138 | 811 |
|
49931 | 812 |
// Make sure we are synchronized on the class loader before we proceed |
813 |
// |
|
814 |
// Note: currently, find_or_load_shared_class is called only from |
|
815 |
// JVM_FindLoadedClass and used for PlatformClassLoader and AppClassLoader, |
|
816 |
// which are parallel-capable loaders, so this lock is NOT taken. |
|
817 |
Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
|
818 |
check_loader_lock_contention(lockObject, THREAD); |
|
819 |
ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
|
820 |
||
821 |
{ |
|
822 |
MutexLocker mu(SystemDictionary_lock, THREAD); |
|
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
823 |
InstanceKlass* check = find_class(d_hash, name, dictionary); |
49931 | 824 |
if (check != NULL) { |
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
825 |
return check; |
49931 | 826 |
} |
827 |
} |
|
828 |
||
829 |
k = load_shared_class_for_builtin_loader(name, class_loader, THREAD); |
|
830 |
if (k != NULL) { |
|
831 |
define_instance_class(k, CHECK_NULL); |
|
48138 | 832 |
} |
833 |
} |
|
834 |
} |
|
835 |
return k; |
|
836 |
} |
|
837 |
||
838 |
InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader( |
|
839 |
Symbol* class_name, Handle class_loader, TRAPS) { |
|
49931 | 840 |
assert(UseSharedSpaces, "must be"); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
841 |
InstanceKlass* ik = find_builtin_class(class_name); |
48138 | 842 |
|
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
843 |
if (ik != NULL) { |
48138 | 844 |
if ((ik->is_shared_app_class() && |
845 |
SystemDictionary::is_system_class_loader(class_loader())) || |
|
846 |
(ik->is_shared_platform_class() && |
|
847 |
SystemDictionary::is_platform_class_loader(class_loader()))) { |
|
848 |
Handle protection_domain = |
|
849 |
SystemDictionaryShared::init_security_info(class_loader, ik, CHECK_NULL); |
|
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
53249
diff
changeset
|
850 |
return load_shared_class(ik, class_loader, protection_domain, NULL, THREAD); |
48138 | 851 |
} |
852 |
} |
|
853 |
return NULL; |
|
854 |
} |
|
855 |
||
856 |
void SystemDictionaryShared::oops_do(OopClosure* f) { |
|
857 |
f->do_oop((oop*)&_shared_protection_domains); |
|
858 |
f->do_oop((oop*)&_shared_jar_urls); |
|
859 |
f->do_oop((oop*)&_shared_jar_manifests); |
|
860 |
} |
|
861 |
||
862 |
void SystemDictionaryShared::allocate_shared_protection_domain_array(int size, TRAPS) { |
|
863 |
if (_shared_protection_domains == NULL) { |
|
864 |
_shared_protection_domains = oopFactory::new_objArray( |
|
865 |
SystemDictionary::ProtectionDomain_klass(), size, CHECK); |
|
866 |
} |
|
867 |
} |
|
868 |
||
869 |
void SystemDictionaryShared::allocate_shared_jar_url_array(int size, TRAPS) { |
|
870 |
if (_shared_jar_urls == NULL) { |
|
871 |
_shared_jar_urls = oopFactory::new_objArray( |
|
872 |
SystemDictionary::URL_klass(), size, CHECK); |
|
873 |
} |
|
874 |
} |
|
875 |
||
876 |
void SystemDictionaryShared::allocate_shared_jar_manifest_array(int size, TRAPS) { |
|
877 |
if (_shared_jar_manifests == NULL) { |
|
878 |
_shared_jar_manifests = oopFactory::new_objArray( |
|
879 |
SystemDictionary::Jar_Manifest_klass(), size, CHECK); |
|
880 |
} |
|
881 |
} |
|
882 |
||
883 |
void SystemDictionaryShared::allocate_shared_data_arrays(int size, TRAPS) { |
|
884 |
allocate_shared_protection_domain_array(size, CHECK); |
|
885 |
allocate_shared_jar_url_array(size, CHECK); |
|
886 |
allocate_shared_jar_manifest_array(size, CHECK); |
|
887 |
} |
|
888 |
||
49931 | 889 |
// This function is called for loading only UNREGISTERED classes |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
890 |
InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name, |
48138 | 891 |
Handle class_loader, |
892 |
Handle protection_domain, |
|
893 |
const ClassFileStream* cfs, |
|
894 |
TRAPS) { |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
895 |
if (!UseSharedSpaces) { |
48138 | 896 |
return NULL; |
897 |
} |
|
898 |
if (class_name == NULL) { // don't do this for anonymous classes |
|
899 |
return NULL; |
|
900 |
} |
|
901 |
if (class_loader.is_null() || |
|
902 |
SystemDictionary::is_system_class_loader(class_loader()) || |
|
903 |
SystemDictionary::is_platform_class_loader(class_loader())) { |
|
904 |
// Do nothing for the BUILTIN loaders. |
|
905 |
return NULL; |
|
906 |
} |
|
907 |
||
58542
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
908 |
const RunTimeSharedClassInfo* record = find_record(&_unregistered_dictionary, &_dynamic_unregistered_dictionary, class_name); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
909 |
if (record == NULL) { |
58542
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
910 |
return NULL; |
48138 | 911 |
} |
912 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
913 |
int clsfile_size = cfs->length(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
914 |
int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length()); |
54927 | 915 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
916 |
if (!record->matches(clsfile_size, clsfile_crc32)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
917 |
return NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
918 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
919 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
920 |
return acquire_class_for_current_thread(record->_klass, class_loader, |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
53249
diff
changeset
|
921 |
protection_domain, cfs, |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
53249
diff
changeset
|
922 |
THREAD); |
48138 | 923 |
} |
924 |
||
925 |
InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread( |
|
926 |
InstanceKlass *ik, |
|
927 |
Handle class_loader, |
|
928 |
Handle protection_domain, |
|
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
53249
diff
changeset
|
929 |
const ClassFileStream *cfs, |
48138 | 930 |
TRAPS) { |
931 |
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader()); |
|
932 |
||
933 |
{ |
|
934 |
MutexLocker mu(SharedDictionary_lock, THREAD); |
|
935 |
if (ik->class_loader_data() != NULL) { |
|
936 |
// ik is already loaded (by this loader or by a different loader) |
|
937 |
// or ik is being loaded by a different thread (by this loader or by a different loader) |
|
938 |
return NULL; |
|
939 |
} |
|
940 |
||
941 |
// No other thread has acquired this yet, so give it to *this thread* |
|
942 |
ik->set_class_loader_data(loader_data); |
|
943 |
} |
|
944 |
||
945 |
// No longer holding SharedDictionary_lock |
|
946 |
// No need to lock, as <ik> can be held only by a single thread. |
|
947 |
loader_data->add_class(ik); |
|
948 |
||
949 |
// Load and check super/interfaces, restore unsharable info |
|
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
53249
diff
changeset
|
950 |
InstanceKlass* shared_klass = load_shared_class(ik, class_loader, protection_domain, |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
53249
diff
changeset
|
951 |
cfs, THREAD); |
48138 | 952 |
if (shared_klass == NULL || HAS_PENDING_EXCEPTION) { |
953 |
// TODO: clean up <ik> so it can be used again |
|
954 |
return NULL; |
|
955 |
} |
|
956 |
||
957 |
return shared_klass; |
|
958 |
} |
|
959 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
960 |
static ResourceHashtable< |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
961 |
Symbol*, bool, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
962 |
primitive_hash<Symbol*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
963 |
primitive_equals<Symbol*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
964 |
6661, // prime number |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
965 |
ResourceObj::C_HEAP> _loaded_unregistered_classes; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
966 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
967 |
bool SystemDictionaryShared::add_unregistered_class(InstanceKlass* k, TRAPS) { |
48138 | 968 |
assert(DumpSharedSpaces, "only when dumping"); |
969 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
970 |
Symbol* name = k->name(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
971 |
if (_loaded_unregistered_classes.get(name) != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
972 |
// We don't allow duplicated unregistered classes of the same name. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
973 |
return false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
974 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
975 |
bool isnew = _loaded_unregistered_classes.put(name, true); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
976 |
assert(isnew, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
977 |
MutexLocker mu_r(Compile_lock, THREAD); // add_to_hierarchy asserts this. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
978 |
SystemDictionary::add_to_hierarchy(k, CHECK_0); |
48138 | 979 |
return true; |
980 |
} |
|
981 |
} |
|
982 |
||
983 |
// This function is called to resolve the super/interfaces of shared classes for |
|
984 |
// non-built-in loaders. E.g., ChildClass in the below example |
|
985 |
// where "super:" (and optionally "interface:") have been specified. |
|
986 |
// |
|
987 |
// java/lang/Object id: 0 |
|
988 |
// Interface id: 2 super: 0 source: cust.jar |
|
989 |
// ChildClass id: 4 super: 0 interfaces: 2 source: cust.jar |
|
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
990 |
InstanceKlass* SystemDictionaryShared::dump_time_resolve_super_or_fail( |
48138 | 991 |
Symbol* child_name, Symbol* class_name, Handle class_loader, |
992 |
Handle protection_domain, bool is_superclass, TRAPS) { |
|
993 |
||
994 |
assert(DumpSharedSpaces, "only when dumping"); |
|
995 |
||
996 |
ClassListParser* parser = ClassListParser::instance(); |
|
997 |
if (parser == NULL) { |
|
998 |
// We're still loading the well-known classes, before the ClassListParser is created. |
|
999 |
return NULL; |
|
1000 |
} |
|
1001 |
if (child_name->equals(parser->current_class_name())) { |
|
1002 |
// When this function is called, all the numbered super and interface types |
|
1003 |
// must have already been loaded. Hence this function is never recursively called. |
|
1004 |
if (is_superclass) { |
|
1005 |
return parser->lookup_super_for_current_class(class_name); |
|
1006 |
} else { |
|
1007 |
return parser->lookup_interface_for_current_class(class_name); |
|
1008 |
} |
|
1009 |
} else { |
|
1010 |
// The VM is not trying to resolve a super type of parser->current_class_name(). |
|
1011 |
// Instead, it's resolving an error class (because parser->current_class_name() has |
|
1012 |
// failed parsing or verification). Don't do anything here. |
|
1013 |
return NULL; |
|
1014 |
} |
|
1015 |
} |
|
1016 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1017 |
DumpTimeSharedClassInfo* SystemDictionaryShared::find_or_allocate_info_for(InstanceKlass* k) { |
54927 | 1018 |
MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1019 |
if (_dumptime_table == NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1020 |
_dumptime_table = new (ResourceObj::C_HEAP, mtClass)DumpTimeSharedClassTable(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1021 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1022 |
return _dumptime_table->find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1023 |
} |
48138 | 1024 |
|
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
1025 |
void SystemDictionaryShared::set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs) { |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58096
diff
changeset
|
1026 |
Arguments::assert_is_dumping_archive(); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1027 |
assert(!is_builtin(k), "must be unregistered class"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1028 |
DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1029 |
info->_clsfile_size = cfs->length(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1030 |
info->_clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1031 |
} |
48138 | 1032 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1033 |
void SystemDictionaryShared::init_dumptime_info(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1034 |
(void)find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1035 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1036 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1037 |
void SystemDictionaryShared::remove_dumptime_info(InstanceKlass* k) { |
54927 | 1038 |
MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag); |
1039 |
DumpTimeSharedClassInfo* p = _dumptime_table->get(k); |
|
1040 |
if (p == NULL) { |
|
1041 |
return; |
|
1042 |
} |
|
1043 |
if (p->_verifier_constraints != NULL) { |
|
1044 |
for (int i = 0; i < p->_verifier_constraints->length(); i++) { |
|
1045 |
DumpTimeSharedClassInfo::DTConstraint constraint = p->_verifier_constraints->at(i); |
|
1046 |
if (constraint._name != NULL ) { |
|
1047 |
constraint._name->decrement_refcount(); |
|
1048 |
} |
|
1049 |
if (constraint._from_name != NULL ) { |
|
1050 |
constraint._from_name->decrement_refcount(); |
|
1051 |
} |
|
1052 |
} |
|
1053 |
FREE_C_HEAP_ARRAY(DTConstraint, p->_verifier_constraints); |
|
1054 |
p->_verifier_constraints = NULL; |
|
1055 |
} |
|
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
54927
diff
changeset
|
1056 |
FREE_C_HEAP_ARRAY(char, p->_verifier_constraint_flags); |
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
54927
diff
changeset
|
1057 |
p->_verifier_constraint_flags = NULL; |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1058 |
_dumptime_table->remove(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1059 |
} |
48138 | 1060 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1061 |
bool SystemDictionaryShared::is_jfr_event_class(InstanceKlass *k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1062 |
while (k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1063 |
if (k->name()->equals("jdk/internal/event/Event")) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1064 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1065 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1066 |
k = k->java_super(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1067 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1068 |
return false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1069 |
} |
48138 | 1070 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1071 |
void SystemDictionaryShared::warn_excluded(InstanceKlass* k, const char* reason) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1072 |
ResourceMark rm; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1073 |
log_warning(cds)("Skipping %s: %s", k->name()->as_C_string(), reason); |
48138 | 1074 |
} |
1075 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1076 |
bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1077 |
if (k->class_loader_data()->is_unsafe_anonymous()) { |
54927 | 1078 |
warn_excluded(k, "Unsafe anonymous class"); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1079 |
return true; // unsafe anonymous classes are not archived, skip |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1080 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1081 |
if (k->is_in_error_state()) { |
54927 | 1082 |
warn_excluded(k, "In error state"); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1083 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1084 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1085 |
if (k->shared_classpath_index() < 0 && is_builtin(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1086 |
// These are classes loaded from unsupported locations (such as those loaded by JVMTI native |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1087 |
// agent during dump time). |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1088 |
warn_excluded(k, "Unsupported location"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1089 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1090 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1091 |
if (k->signers() != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1092 |
// We cannot include signed classes in the archive because the certificates |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1093 |
// used during dump time may be different than those used during |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1094 |
// runtime (due to expiration, etc). |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1095 |
warn_excluded(k, "Signed JAR"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1096 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1097 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1098 |
if (is_jfr_event_class(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1099 |
// We cannot include JFR event classes because they need runtime-specific |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1100 |
// instrumentation in order to work with -XX:FlightRecorderOptions=retransform=false. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1101 |
// There are only a small number of these classes, so it's not worthwhile to |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1102 |
// support them and make CDS more complicated. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1103 |
warn_excluded(k, "JFR event class"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1104 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1105 |
} |
54927 | 1106 |
if (k->init_state() < InstanceKlass::linked) { |
1107 |
// In static dumping, we will attempt to link all classes. Those that fail to link will |
|
1108 |
// be marked as in error state. |
|
1109 |
assert(DynamicDumpSharedSpaces, "must be"); |
|
1110 |
||
1111 |
// TODO -- rethink how this can be handled. |
|
1112 |
// We should try to link ik, however, we can't do it here because |
|
1113 |
// 1. We are at VM exit |
|
1114 |
// 2. linking a class may cause other classes to be loaded, which means |
|
1115 |
// a custom ClassLoader.loadClass() may be called, at a point where the |
|
1116 |
// class loader doesn't expect it. |
|
1117 |
warn_excluded(k, "Not linked"); |
|
1118 |
return true; |
|
1119 |
} |
|
1120 |
if (k->major_version() < 50 /*JAVA_6_VERSION*/) { |
|
1121 |
ResourceMark rm; |
|
1122 |
log_warning(cds)("Pre JDK 6 class not supported by CDS: %u.%u %s", |
|
1123 |
k->major_version(), k->minor_version(), k->name()->as_C_string()); |
|
1124 |
return true; |
|
1125 |
} |
|
1126 |
||
1127 |
InstanceKlass* super = k->java_super(); |
|
1128 |
if (super != NULL && should_be_excluded(super)) { |
|
1129 |
ResourceMark rm; |
|
1130 |
log_warning(cds)("Skipping %s: super class %s is excluded", k->name()->as_C_string(), super->name()->as_C_string()); |
|
1131 |
return true; |
|
1132 |
} |
|
1133 |
||
1134 |
Array<InstanceKlass*>* interfaces = k->local_interfaces(); |
|
1135 |
int len = interfaces->length(); |
|
1136 |
for (int i = 0; i < len; i++) { |
|
1137 |
InstanceKlass* intf = interfaces->at(i); |
|
1138 |
if (should_be_excluded(intf)) { |
|
1139 |
log_warning(cds)("Skipping %s: interface %s is excluded", k->name()->as_C_string(), intf->name()->as_C_string()); |
|
1140 |
return true; |
|
1141 |
} |
|
1142 |
} |
|
1143 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1144 |
return false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1145 |
} |
48138 | 1146 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1147 |
// k is a class before relocating by ArchiveCompactor |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1148 |
void SystemDictionaryShared::validate_before_archiving(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1149 |
ResourceMark rm; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1150 |
const char* name = k->name()->as_C_string(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1151 |
DumpTimeSharedClassInfo* info = _dumptime_table->get(k); |
54927 | 1152 |
assert(_no_class_loading_should_happen, "class loading must be disabled"); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1153 |
guarantee(info != NULL, "Class %s must be entered into _dumptime_table", name); |
54927 | 1154 |
guarantee(!info->is_excluded(), "Should not attempt to archive excluded class %s", name); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1155 |
if (is_builtin(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1156 |
guarantee(k->loader_type() != 0, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1157 |
"Class loader type must be set for BUILTIN class %s", name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1158 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1159 |
guarantee(k->loader_type() == 0, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1160 |
"Class loader type must not be set for UNREGISTERED class %s", name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1161 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1162 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1163 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1164 |
class ExcludeDumpTimeSharedClasses : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1165 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1166 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1167 |
if (SystemDictionaryShared::should_be_excluded(k)) { |
54927 | 1168 |
info.set_excluded(); |
48138 | 1169 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1170 |
return true; // keep on iterating |
48138 | 1171 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1172 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1173 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1174 |
void SystemDictionaryShared::check_excluded_classes() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1175 |
ExcludeDumpTimeSharedClasses excl; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1176 |
_dumptime_table->iterate(&excl); |
54927 | 1177 |
_dumptime_table->update_counts(); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1178 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1179 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1180 |
bool SystemDictionaryShared::is_excluded_class(InstanceKlass* k) { |
54927 | 1181 |
assert(_no_class_loading_should_happen, "sanity"); |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58096
diff
changeset
|
1182 |
Arguments::assert_is_dumping_archive(); |
54927 | 1183 |
return find_or_allocate_info_for(k)->is_excluded(); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1184 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1185 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1186 |
class IterateDumpTimeSharedClassTable : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1187 |
MetaspaceClosure *_it; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1188 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1189 |
IterateDumpTimeSharedClassTable(MetaspaceClosure* it) : _it(it) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1190 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1191 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
54927 | 1192 |
if (!info.is_excluded()) { |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1193 |
info.metaspace_pointers_do(_it); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1194 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1195 |
return true; // keep on iterating |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1196 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1197 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1198 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1199 |
void SystemDictionaryShared::dumptime_classes_do(class MetaspaceClosure* it) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1200 |
IterateDumpTimeSharedClassTable iter(it); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1201 |
_dumptime_table->iterate(&iter); |
48138 | 1202 |
} |
1203 |
||
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
1204 |
bool SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbol* name, |
48138 | 1205 |
Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) { |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
58096
diff
changeset
|
1206 |
Arguments::assert_is_dumping_archive(); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1207 |
DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1208 |
info->add_verification_constraint(k, name, from_name, from_field_is_protected, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1209 |
from_is_array, from_is_object); |
54927 | 1210 |
|
1211 |
if (DynamicDumpSharedSpaces) { |
|
1212 |
// For dynamic dumping, we can resolve all the constraint classes for all class loaders during |
|
1213 |
// the initial run prior to creating the archive before vm exit. We will also perform verification |
|
1214 |
// check when running with the archive. |
|
48138 | 1215 |
return false; |
1216 |
} else { |
|
54927 | 1217 |
if (is_builtin(k)) { |
1218 |
// For builtin class loaders, we can try to complete the verification check at dump time, |
|
1219 |
// because we can resolve all the constraint classes. We will also perform verification check |
|
1220 |
// when running with the archive. |
|
1221 |
return false; |
|
1222 |
} else { |
|
1223 |
// For non-builtin class loaders, we cannot complete the verification check at dump time, |
|
1224 |
// because at dump time we don't know how to resolve classes for such loaders. |
|
1225 |
return true; |
|
1226 |
} |
|
48138 | 1227 |
} |
1228 |
} |
|
1229 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1230 |
void DumpTimeSharedClassInfo::add_verification_constraint(InstanceKlass* k, Symbol* name, |
48138 | 1231 |
Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) { |
1232 |
if (_verifier_constraints == NULL) { |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1233 |
_verifier_constraints = new(ResourceObj::C_HEAP, mtClass) GrowableArray<DTConstraint>(4, true, mtClass); |
48138 | 1234 |
} |
1235 |
if (_verifier_constraint_flags == NULL) { |
|
1236 |
_verifier_constraint_flags = new(ResourceObj::C_HEAP, mtClass) GrowableArray<char>(4, true, mtClass); |
|
1237 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1238 |
GrowableArray<DTConstraint>* vc_array = _verifier_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1239 |
for (int i = 0; i < vc_array->length(); i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1240 |
DTConstraint* p = vc_array->adr_at(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1241 |
if (name == p->_name && from_name == p->_from_name) { |
48138 | 1242 |
return; |
1243 |
} |
|
1244 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1245 |
DTConstraint cons(name, from_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1246 |
vc_array->append(cons); |
48138 | 1247 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1248 |
GrowableArray<char>* vcflags_array = _verifier_constraint_flags; |
48138 | 1249 |
char c = 0; |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1250 |
c |= from_field_is_protected ? SystemDictionaryShared::FROM_FIELD_IS_PROTECTED : 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1251 |
c |= from_is_array ? SystemDictionaryShared::FROM_IS_ARRAY : 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1252 |
c |= from_is_object ? SystemDictionaryShared::FROM_IS_OBJECT : 0; |
48138 | 1253 |
vcflags_array->append(c); |
1254 |
||
1255 |
if (log_is_enabled(Trace, cds, verification)) { |
|
1256 |
ResourceMark rm; |
|
54927 | 1257 |
log_trace(cds, verification)("add_verification_constraint: %s: %s must be subclass of %s [0x%x]", |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1258 |
k->external_name(), from_name->as_klass_external_name(), |
54927 | 1259 |
name->as_klass_external_name(), c); |
48138 | 1260 |
} |
1261 |
} |
|
1262 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1263 |
void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1264 |
TRAPS) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1265 |
assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1266 |
RunTimeSharedClassInfo* record = RunTimeSharedClassInfo::get_for(klass); |
48138 | 1267 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1268 |
int length = record->_num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1269 |
if (length > 0) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1270 |
for (int i = 0; i < length; i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1271 |
Symbol* name = record->get_constraint_name(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1272 |
Symbol* from_name = record->get_constraint_from_name(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1273 |
char c = record->get_constraint_flag(i); |
48138 | 1274 |
|
54927 | 1275 |
if (log_is_enabled(Trace, cds, verification)) { |
1276 |
ResourceMark rm(THREAD); |
|
1277 |
log_trace(cds, verification)("check_verification_constraint: %s: %s must be subclass of %s [0x%x]", |
|
1278 |
klass->external_name(), from_name->as_klass_external_name(), |
|
1279 |
name->as_klass_external_name(), c); |
|
1280 |
} |
|
1281 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1282 |
bool from_field_is_protected = (c & SystemDictionaryShared::FROM_FIELD_IS_PROTECTED) ? true : false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1283 |
bool from_is_array = (c & SystemDictionaryShared::FROM_IS_ARRAY) ? true : false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1284 |
bool from_is_object = (c & SystemDictionaryShared::FROM_IS_OBJECT) ? true : false; |
48138 | 1285 |
|
1286 |
bool ok = VerificationType::resolve_and_check_assignability(klass, name, |
|
1287 |
from_name, from_field_is_protected, from_is_array, from_is_object, CHECK); |
|
1288 |
if (!ok) { |
|
1289 |
ResourceMark rm(THREAD); |
|
1290 |
stringStream ss; |
|
1291 |
||
1292 |
ss.print_cr("Bad type on operand stack"); |
|
1293 |
ss.print_cr("Exception Details:"); |
|
1294 |
ss.print_cr(" Location:\n %s", klass->name()->as_C_string()); |
|
1295 |
ss.print_cr(" Reason:\n Type '%s' is not assignable to '%s'", |
|
1296 |
from_name->as_quoted_ascii(), name->as_quoted_ascii()); |
|
1297 |
THROW_MSG(vmSymbols::java_lang_VerifyError(), ss.as_string()); |
|
1298 |
} |
|
1299 |
} |
|
1300 |
} |
|
1301 |
} |
|
1302 |
||
54927 | 1303 |
class EstimateSizeForArchive : StackObj { |
1304 |
size_t _shared_class_info_size; |
|
1305 |
int _num_builtin_klasses; |
|
1306 |
int _num_unregistered_klasses; |
|
1307 |
||
1308 |
public: |
|
1309 |
EstimateSizeForArchive() { |
|
1310 |
_shared_class_info_size = 0; |
|
1311 |
_num_builtin_klasses = 0; |
|
1312 |
_num_unregistered_klasses = 0; |
|
1313 |
} |
|
1314 |
||
1315 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
|
1316 |
if (!info.is_excluded()) { |
|
1317 |
size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_constraints()); |
|
1318 |
_shared_class_info_size += align_up(byte_size, BytesPerWord); |
|
1319 |
} |
|
1320 |
return true; // keep on iterating |
|
1321 |
} |
|
1322 |
||
1323 |
size_t total() { |
|
1324 |
return _shared_class_info_size; |
|
1325 |
} |
|
1326 |
}; |
|
1327 |
||
1328 |
size_t SystemDictionaryShared::estimate_size_for_archive() { |
|
1329 |
EstimateSizeForArchive est; |
|
1330 |
_dumptime_table->iterate(&est); |
|
1331 |
return est.total() + |
|
1332 |
CompactHashtableWriter::estimate_size(_dumptime_table->count_of(true)) + |
|
1333 |
CompactHashtableWriter::estimate_size(_dumptime_table->count_of(false)); |
|
1334 |
} |
|
1335 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1336 |
class CopySharedClassInfoToArchive : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1337 |
CompactHashtableWriter* _writer; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1338 |
bool _is_builtin; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1339 |
public: |
54927 | 1340 |
CopySharedClassInfoToArchive(CompactHashtableWriter* writer, |
1341 |
bool is_builtin, |
|
1342 |
bool is_static_archive) |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1343 |
: _writer(writer), _is_builtin(is_builtin) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1344 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1345 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
54927 | 1346 |
if (!info.is_excluded() && info.is_builtin() == _is_builtin) { |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1347 |
size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_constraints()); |
54927 | 1348 |
RunTimeSharedClassInfo* record; |
1349 |
record = (RunTimeSharedClassInfo*)MetaspaceShared::read_only_space_alloc(byte_size); |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1350 |
record->init(info); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1351 |
|
54927 | 1352 |
unsigned int hash; |
1353 |
Symbol* name = info._klass->name(); |
|
1354 |
if (DynamicDumpSharedSpaces) { |
|
1355 |
name = DynamicArchive::original_to_target(name); |
|
1356 |
} |
|
1357 |
hash = primitive_hash<Symbol*>(name); |
|
1358 |
u4 delta; |
|
1359 |
if (DynamicDumpSharedSpaces) { |
|
1360 |
delta = MetaspaceShared::object_delta_u4(DynamicArchive::buffer_to_target(record)); |
|
1361 |
} else { |
|
1362 |
delta = MetaspaceShared::object_delta_u4(record); |
|
1363 |
} |
|
1364 |
_writer->add(hash, delta); |
|
1365 |
if (log_is_enabled(Trace, cds, hashtables)) { |
|
1366 |
ResourceMark rm; |
|
1367 |
log_trace(cds,hashtables)("%s dictionary: %s", (_is_builtin ? "builtin" : "unregistered"), info._klass->external_name()); |
|
1368 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1369 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1370 |
// Save this for quick runtime lookup of InstanceKlass* -> RunTimeSharedClassInfo* |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1371 |
RunTimeSharedClassInfo::set_for(info._klass, record); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1372 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1373 |
return true; // keep on iterating |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1374 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1375 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1376 |
|
54927 | 1377 |
void SystemDictionaryShared::write_dictionary(RunTimeSharedDictionary* dictionary, |
1378 |
bool is_builtin, |
|
1379 |
bool is_static_archive) { |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1380 |
CompactHashtableStats stats; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1381 |
dictionary->reset(); |
54927 | 1382 |
CompactHashtableWriter writer(_dumptime_table->count_of(is_builtin), &stats); |
1383 |
CopySharedClassInfoToArchive copy(&writer, is_builtin, is_static_archive); |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1384 |
_dumptime_table->iterate(©); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1385 |
writer.dump(dictionary, is_builtin ? "builtin dictionary" : "unregistered dictionary"); |
48138 | 1386 |
} |
1387 |
||
54927 | 1388 |
void SystemDictionaryShared::write_to_archive(bool is_static_archive) { |
1389 |
if (is_static_archive) { |
|
1390 |
write_dictionary(&_builtin_dictionary, true); |
|
1391 |
write_dictionary(&_unregistered_dictionary, false); |
|
1392 |
} else { |
|
1393 |
write_dictionary(&_dynamic_builtin_dictionary, true); |
|
1394 |
write_dictionary(&_dynamic_unregistered_dictionary, false); |
|
1395 |
} |
|
48138 | 1396 |
} |
1397 |
||
54927 | 1398 |
void SystemDictionaryShared::serialize_dictionary_headers(SerializeClosure* soc, |
1399 |
bool is_static_archive) { |
|
1400 |
if (is_static_archive) { |
|
1401 |
_builtin_dictionary.serialize_header(soc); |
|
1402 |
_unregistered_dictionary.serialize_header(soc); |
|
1403 |
} else { |
|
1404 |
_dynamic_builtin_dictionary.serialize_header(soc); |
|
1405 |
_dynamic_unregistered_dictionary.serialize_header(soc); |
|
1406 |
} |
|
48138 | 1407 |
} |
1408 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1409 |
const RunTimeSharedClassInfo* |
58542
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1410 |
SystemDictionaryShared::find_record(RunTimeSharedDictionary* static_dict, RunTimeSharedDictionary* dynamic_dict, Symbol* name) { |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1411 |
if (!UseSharedSpaces || !name->is_shared()) { |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1412 |
// The names of all shared classes must also be a shared Symbol. |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1413 |
return NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1414 |
} |
58542
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1415 |
|
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1416 |
unsigned int hash = primitive_hash<Symbol*>(name); |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1417 |
const RunTimeSharedClassInfo* record = NULL; |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1418 |
if (!MetaspaceShared::is_shared_dynamic(name)) { |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1419 |
// The names of all shared classes in the static dict must also be in the |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1420 |
// static archive |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1421 |
record = static_dict->lookup(name, hash, 0); |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1422 |
} |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1423 |
|
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1424 |
if (record == NULL && DynamicArchive::is_mapped()) { |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1425 |
record = dynamic_dict->lookup(name, hash, 0); |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1426 |
} |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1427 |
|
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1428 |
return record; |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1429 |
} |
48138 | 1430 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1431 |
InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) { |
58542
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1432 |
const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, &_dynamic_builtin_dictionary, name); |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1433 |
if (record != NULL) { |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1434 |
return record->_klass; |
58542
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1435 |
} else { |
94fe833a244b
8232071: Avoid shared dictionary lookup when the class name is not shared
iklam
parents:
58499
diff
changeset
|
1436 |
return NULL; |
48138 | 1437 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1438 |
} |
48138 | 1439 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1440 |
void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1441 |
assert(DumpSharedSpaces, "supported only when dumping"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1442 |
DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1443 |
info->_id = id; |
48138 | 1444 |
} |
1445 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1446 |
class SharedDictionaryPrinter : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1447 |
outputStream* _st; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1448 |
int _index; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1449 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1450 |
SharedDictionaryPrinter(outputStream* st) : _st(st), _index(0) {} |
48138 | 1451 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1452 |
void do_value(const RunTimeSharedClassInfo* record) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1453 |
ResourceMark rm; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1454 |
_st->print_cr("%4d: %s", (_index++), record->_klass->external_name()); |
48138 | 1455 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1456 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1457 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1458 |
void SystemDictionaryShared::print_on(outputStream* st) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1459 |
if (UseSharedSpaces) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1460 |
st->print_cr("Shared Dictionary"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1461 |
SharedDictionaryPrinter p(st); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1462 |
_builtin_dictionary.iterate(&p); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1463 |
_unregistered_dictionary.iterate(&p); |
54927 | 1464 |
if (DynamicArchive::is_mapped()) { |
1465 |
_dynamic_builtin_dictionary.iterate(&p); |
|
1466 |
_unregistered_dictionary.iterate(&p); |
|
1467 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1468 |
} |
48138 | 1469 |
} |
1470 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1471 |
void SystemDictionaryShared::print_table_statistics(outputStream* st) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1472 |
if (UseSharedSpaces) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1473 |
_builtin_dictionary.print_table_statistics(st, "Builtin Shared Dictionary"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1474 |
_unregistered_dictionary.print_table_statistics(st, "Unregistered Shared Dictionary"); |
54927 | 1475 |
if (DynamicArchive::is_mapped()) { |
1476 |
_dynamic_builtin_dictionary.print_table_statistics(st, "Dynamic Builtin Shared Dictionary"); |
|
1477 |
_dynamic_unregistered_dictionary.print_table_statistics(st, "Unregistered Shared Dictionary"); |
|
1478 |
} |
|
48138 | 1479 |
} |
1480 |
} |
|
54927 | 1481 |
|
1482 |
bool SystemDictionaryShared::empty_dumptime_table() { |
|
1483 |
if (_dumptime_table == NULL) { |
|
1484 |
return true; |
|
1485 |
} |
|
1486 |
_dumptime_table->update_counts(); |
|
1487 |
if (_dumptime_table->count_of(true) == 0 && _dumptime_table->count_of(false) == 0){ |
|
1488 |
return true; |
|
1489 |
} |
|
1490 |
return false; |
|
1491 |
} |