author | redestad |
Thu, 20 Dec 2018 19:44:08 +0100 | |
changeset 53091 | 5bf5b773fc41 |
parent 52514 | f4e3900c8d08 |
child 53249 | fbab5d82f3d7 |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
49041
44122f767467
8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents:
48138
diff
changeset
|
2 |
* Copyright (c) 2014, 2018, 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" |
|
46 |
#include "oops/instanceKlass.hpp" |
|
47 |
#include "oops/klass.inline.hpp" |
|
48 |
#include "oops/objArrayOop.inline.hpp" |
|
49 |
#include "oops/oop.inline.hpp" |
|
49041
44122f767467
8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents:
48138
diff
changeset
|
50 |
#include "oops/typeArrayOop.inline.hpp" |
49393 | 51 |
#include "runtime/handles.inline.hpp" |
48138 | 52 |
#include "runtime/java.hpp" |
53 |
#include "runtime/javaCalls.hpp" |
|
54 |
#include "runtime/mutexLocker.hpp" |
|
55 |
#include "utilities/hashtable.inline.hpp" |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
56 |
#include "utilities/resourceHash.hpp" |
48138 | 57 |
#include "utilities/stringUtils.hpp" |
58 |
||
59 |
||
60 |
objArrayOop SystemDictionaryShared::_shared_protection_domains = NULL; |
|
61 |
objArrayOop SystemDictionaryShared::_shared_jar_urls = NULL; |
|
62 |
objArrayOop SystemDictionaryShared::_shared_jar_manifests = NULL; |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
63 |
DEBUG_ONLY(bool SystemDictionaryShared::_checked_excluded_classes = false;) |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
64 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
65 |
class DumpTimeSharedClassInfo: public CHeapObj<mtClass> { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
66 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
67 |
struct DTConstraint { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
68 |
Symbol* _name; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
69 |
Symbol* _from_name; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
70 |
DTConstraint() : _name(NULL), _from_name(NULL) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
71 |
DTConstraint(Symbol* n, Symbol* fn) : _name(n), _from_name(fn) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
72 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
73 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
74 |
InstanceKlass* _klass; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
75 |
int _id; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
76 |
int _clsfile_size; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
77 |
int _clsfile_crc32; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
78 |
bool _excluded; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
79 |
GrowableArray<DTConstraint>* _verifier_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
80 |
GrowableArray<char>* _verifier_constraint_flags; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
81 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
82 |
DumpTimeSharedClassInfo() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
83 |
_klass = NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
84 |
_id = -1; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
85 |
_clsfile_size = -1; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
86 |
_clsfile_crc32 = -1; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
87 |
_excluded = false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
88 |
_verifier_constraints = NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
89 |
_verifier_constraint_flags = NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
90 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
91 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
92 |
void add_verification_constraint(InstanceKlass* k, Symbol* name, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
93 |
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
|
94 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
95 |
bool is_builtin() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
96 |
return SystemDictionaryShared::is_builtin(_klass); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
97 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
98 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
99 |
int num_constraints() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
100 |
if (_verifier_constraint_flags != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
101 |
return _verifier_constraint_flags->length(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
102 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
103 |
return 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
104 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
105 |
} |
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 |
void metaspace_pointers_do(MetaspaceClosure* it) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
108 |
it->push(&_klass); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
109 |
if (_verifier_constraints != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
110 |
for (int i = 0; i < _verifier_constraints->length(); i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
111 |
DTConstraint* cons = _verifier_constraints->adr_at(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
112 |
it->push(&cons->_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
113 |
it->push(&cons->_from_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
114 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
115 |
} |
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 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
119 |
class DumpTimeSharedClassTable: public ResourceHashtable< |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
120 |
InstanceKlass*, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
121 |
DumpTimeSharedClassInfo, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
122 |
primitive_hash<InstanceKlass*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
123 |
primitive_equals<InstanceKlass*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
124 |
15889, // prime number |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
125 |
ResourceObj::C_HEAP> |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
126 |
{ |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
127 |
int _builtin_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
128 |
int _unregistered_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
129 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
130 |
DumpTimeSharedClassInfo* find_or_allocate_info_for(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
131 |
DumpTimeSharedClassInfo* p = get(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
132 |
if (p == NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
133 |
assert(!SystemDictionaryShared::checked_excluded_classes(), |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
134 |
"no new classes can be added after check_excluded_classes"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
135 |
put(k, DumpTimeSharedClassInfo()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
136 |
p = get(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
137 |
assert(p != NULL, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
138 |
p->_klass = k; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
139 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
140 |
return p; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
141 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
142 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
143 |
class CountClassByCategory : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
144 |
DumpTimeSharedClassTable* _table; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
145 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
146 |
CountClassByCategory(DumpTimeSharedClassTable* table) : _table(table) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
147 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
148 |
if (SystemDictionaryShared::is_builtin(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
149 |
++ _table->_builtin_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
150 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
151 |
++ _table->_unregistered_count; |
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 |
return true; // keep on iterating |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
154 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
155 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
156 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
157 |
void update_counts() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
158 |
CountClassByCategory counter(this); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
159 |
iterate(&counter); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
160 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
161 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
162 |
int count_of(bool is_builtin) const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
163 |
if (is_builtin) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
164 |
return _builtin_count; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
165 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
166 |
return _unregistered_count; |
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 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
171 |
class RunTimeSharedClassInfo { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
172 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
173 |
struct CrcInfo { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
174 |
int _clsfile_size; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
175 |
int _clsfile_crc32; |
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 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
178 |
// This is different than DumpTimeSharedClassInfo::DTConstraint. We use |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
179 |
// u4 instead of Symbol* to save space on 64-bit CPU. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
180 |
struct RTConstraint { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
181 |
u4 _name; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
182 |
u4 _from_name; |
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 |
InstanceKlass* _klass; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
186 |
int _num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
187 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
188 |
// optional CrcInfo _crc; (only for UNREGISTERED classes) |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
189 |
// optional RTConstraint _verifier_constraints[_num_constraints] |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
190 |
// optional char _verifier_constraint_flags[_num_constraints] |
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 |
private: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
193 |
static size_t header_size_size() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
194 |
return sizeof(RunTimeSharedClassInfo); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
195 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
196 |
static size_t crc_size(InstanceKlass* klass) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
197 |
if (!SystemDictionaryShared::is_builtin(klass)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
198 |
return sizeof(CrcInfo); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
199 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
200 |
return 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
201 |
} |
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 |
static size_t verifier_constraints_size(int num_constraints) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
204 |
return sizeof(RTConstraint) * num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
205 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
206 |
static size_t verifier_constraint_flags_size(int num_constraints) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
207 |
return sizeof(char) * num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
208 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
209 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
210 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
211 |
static size_t byte_size(InstanceKlass* klass, int num_constraints) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
212 |
return header_size_size() + |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
213 |
crc_size(klass) + |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
214 |
verifier_constraints_size(num_constraints) + |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
215 |
verifier_constraint_flags_size(num_constraints); |
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 |
private: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
219 |
size_t crc_offset() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
220 |
return header_size_size(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
221 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
222 |
size_t verifier_constraints_offset() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
223 |
return crc_offset() + crc_size(_klass); |
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 |
size_t verifier_constraint_flags_offset() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
226 |
return verifier_constraints_offset() + verifier_constraints_size(_num_constraints); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
227 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
228 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
229 |
void check_constraint_offset(int i) const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
230 |
assert(0 <= i && i < _num_constraints, "sanity"); |
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 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
234 |
CrcInfo* crc() const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
235 |
assert(crc_size(_klass) > 0, "must be"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
236 |
return (CrcInfo*)(address(this) + crc_offset()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
237 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
238 |
RTConstraint* verifier_constraints() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
239 |
assert(_num_constraints > 0, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
240 |
return (RTConstraint*)(address(this) + verifier_constraints_offset()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
241 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
242 |
RTConstraint* verifier_constraint_at(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
243 |
check_constraint_offset(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
244 |
return verifier_constraints() + i; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
245 |
} |
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 |
char* verifier_constraint_flags() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
248 |
assert(_num_constraints > 0, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
249 |
return (char*)(address(this) + verifier_constraint_flags_offset()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
250 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
251 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
252 |
void init(DumpTimeSharedClassInfo& info) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
253 |
_klass = info._klass; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
254 |
_num_constraints = info.num_constraints(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
255 |
if (!SystemDictionaryShared::is_builtin(_klass)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
256 |
CrcInfo* c = crc(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
257 |
c->_clsfile_size = info._clsfile_size; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
258 |
c->_clsfile_crc32 = info._clsfile_crc32; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
259 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
260 |
if (_num_constraints > 0) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
261 |
RTConstraint* constraints = verifier_constraints(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
262 |
char* flags = verifier_constraint_flags(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
263 |
int i; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
264 |
for (i = 0; i < _num_constraints; i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
265 |
constraints[i]._name = MetaspaceShared::object_delta_u4(info._verifier_constraints->at(i)._name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
266 |
constraints[i]._from_name = MetaspaceShared::object_delta_u4(info._verifier_constraints->at(i)._from_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
267 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
268 |
for (i = 0; i < _num_constraints; i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
269 |
flags[i] = info._verifier_constraint_flags->at(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
270 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
271 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
272 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
273 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
274 |
bool matches(int clsfile_size, int clsfile_crc32) const { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
275 |
return crc()->_clsfile_size == clsfile_size && |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
276 |
crc()->_clsfile_crc32 == clsfile_crc32; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
277 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
278 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
279 |
Symbol* get_constraint_name(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
280 |
return (Symbol*)(SharedBaseAddress + verifier_constraint_at(i)->_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
281 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
282 |
Symbol* get_constraint_from_name(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
283 |
return (Symbol*)(SharedBaseAddress + verifier_constraint_at(i)->_from_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
284 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
285 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
286 |
char get_constraint_flag(int i) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
287 |
check_constraint_offset(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
288 |
return verifier_constraint_flags()[i]; |
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 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
291 |
private: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
292 |
// ArchiveCompactor::allocate() has reserved a pointer immediately before |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
293 |
// archived InstanceKlasses. We can use this slot to do a quick |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
294 |
// lookup of InstanceKlass* -> RunTimeSharedClassInfo* without |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
295 |
// building a new hashtable. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
296 |
// |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
297 |
// info_pointer_addr(klass) --> 0x0100 RunTimeSharedClassInfo* |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
298 |
// InstanceKlass* klass --> 0x0108 <C++ vtbl> |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
299 |
// 0x0110 fields from Klass ... |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
300 |
static RunTimeSharedClassInfo** info_pointer_addr(InstanceKlass* klass) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
301 |
return &((RunTimeSharedClassInfo**)klass)[-1]; |
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 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
305 |
static RunTimeSharedClassInfo* get_for(InstanceKlass* klass) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
306 |
return *info_pointer_addr(klass); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
307 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
308 |
static void set_for(InstanceKlass* klass, RunTimeSharedClassInfo* record) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
309 |
*info_pointer_addr(klass) = record; |
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 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
312 |
// Used by RunTimeSharedDictionary to implement OffsetCompactHashtable::EQUALS |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
313 |
static inline bool EQUALS( |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
314 |
const RunTimeSharedClassInfo* value, Symbol* key, int len_unused) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
315 |
return (value->_klass->name() == key); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
316 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
317 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
318 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
319 |
class RunTimeSharedDictionary : public OffsetCompactHashtable< |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
320 |
Symbol*, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
321 |
const RunTimeSharedClassInfo*, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
322 |
RunTimeSharedClassInfo::EQUALS> {}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
323 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
324 |
static DumpTimeSharedClassTable* _dumptime_table = NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
325 |
static RunTimeSharedDictionary _builtin_dictionary; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
326 |
static RunTimeSharedDictionary _unregistered_dictionary; |
48138 | 327 |
|
328 |
oop SystemDictionaryShared::shared_protection_domain(int index) { |
|
329 |
return _shared_protection_domains->obj_at(index); |
|
330 |
} |
|
331 |
||
332 |
oop SystemDictionaryShared::shared_jar_url(int index) { |
|
333 |
return _shared_jar_urls->obj_at(index); |
|
334 |
} |
|
335 |
||
336 |
oop SystemDictionaryShared::shared_jar_manifest(int index) { |
|
337 |
return _shared_jar_manifests->obj_at(index); |
|
338 |
} |
|
339 |
||
340 |
||
341 |
Handle SystemDictionaryShared::get_shared_jar_manifest(int shared_path_index, TRAPS) { |
|
342 |
Handle manifest ; |
|
343 |
if (shared_jar_manifest(shared_path_index) == NULL) { |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
344 |
SharedClassPathEntry* ent = FileMapInfo::shared_path(shared_path_index); |
48138 | 345 |
long size = ent->manifest_size(); |
346 |
if (size <= 0) { |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
347 |
return Handle(); |
48138 | 348 |
} |
349 |
||
350 |
// ByteArrayInputStream bais = new ByteArrayInputStream(buf); |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
351 |
const char* src = ent->manifest(); |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
352 |
assert(src != NULL, "No Manifest data"); |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
353 |
typeArrayOop buf = oopFactory::new_byteArray(size, CHECK_NH); |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
354 |
typeArrayHandle bufhandle(THREAD, buf); |
50389
7e8c0409a747
8198285: More consistent Access API for arraycopy
rkennke
parents:
50152
diff
changeset
|
355 |
ArrayAccess<>::arraycopy_from_native(reinterpret_cast<const jbyte*>(src), |
7e8c0409a747
8198285: More consistent Access API for arraycopy
rkennke
parents:
50152
diff
changeset
|
356 |
buf, typeArrayOopDesc::element_offset<jbyte>(0), size); |
48138 | 357 |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
358 |
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
|
359 |
vmSymbols::byte_array_void_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
360 |
bufhandle, CHECK_NH); |
48138 | 361 |
|
362 |
// manifest = new Manifest(bais) |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
363 |
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
|
364 |
vmSymbols::input_stream_void_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
365 |
bais, CHECK_NH); |
48138 | 366 |
atomic_set_shared_jar_manifest(shared_path_index, manifest()); |
367 |
} |
|
368 |
||
369 |
manifest = Handle(THREAD, shared_jar_manifest(shared_path_index)); |
|
370 |
assert(manifest.not_null(), "sanity"); |
|
371 |
return manifest; |
|
372 |
} |
|
373 |
||
374 |
Handle SystemDictionaryShared::get_shared_jar_url(int shared_path_index, TRAPS) { |
|
375 |
Handle url_h; |
|
376 |
if (shared_jar_url(shared_path_index) == NULL) { |
|
377 |
JavaValue result(T_OBJECT); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
378 |
const char* path = FileMapInfo::shared_path_name(shared_path_index); |
48138 | 379 |
Handle path_string = java_lang_String::create_from_str(path, CHECK_(url_h)); |
380 |
Klass* classLoaders_klass = |
|
381 |
SystemDictionary::jdk_internal_loader_ClassLoaders_klass(); |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
382 |
JavaCalls::call_static(&result, classLoaders_klass, |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
383 |
vmSymbols::toFileURL_name(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
384 |
vmSymbols::toFileURL_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
385 |
path_string, CHECK_(url_h)); |
48138 | 386 |
|
387 |
atomic_set_shared_jar_url(shared_path_index, (oop)result.get_jobject()); |
|
388 |
} |
|
389 |
||
390 |
url_h = Handle(THREAD, shared_jar_url(shared_path_index)); |
|
391 |
assert(url_h.not_null(), "sanity"); |
|
392 |
return url_h; |
|
393 |
} |
|
394 |
||
395 |
Handle SystemDictionaryShared::get_package_name(Symbol* class_name, TRAPS) { |
|
396 |
ResourceMark rm(THREAD); |
|
397 |
Handle pkgname_string; |
|
398 |
char* pkgname = (char*) ClassLoader::package_from_name((const char*) class_name->as_C_string()); |
|
399 |
if (pkgname != NULL) { // Package prefix found |
|
400 |
StringUtils::replace_no_expand(pkgname, "/", "."); |
|
401 |
pkgname_string = java_lang_String::create_from_str(pkgname, |
|
402 |
CHECK_(pkgname_string)); |
|
403 |
} |
|
404 |
return pkgname_string; |
|
405 |
} |
|
406 |
||
407 |
// Define Package for shared app classes from JAR file and also checks for |
|
408 |
// package sealing (all done in Java code) |
|
409 |
// See http://docs.oracle.com/javase/tutorial/deployment/jar/sealman.html |
|
410 |
void SystemDictionaryShared::define_shared_package(Symbol* class_name, |
|
411 |
Handle class_loader, |
|
412 |
Handle manifest, |
|
413 |
Handle url, |
|
414 |
TRAPS) { |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
415 |
assert(SystemDictionary::is_system_class_loader(class_loader()), "unexpected class loader"); |
48138 | 416 |
// get_package_name() returns a NULL handle if the class is in unnamed package |
417 |
Handle pkgname_string = get_package_name(class_name, CHECK); |
|
418 |
if (pkgname_string.not_null()) { |
|
419 |
Klass* app_classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(); |
|
420 |
JavaValue result(T_OBJECT); |
|
421 |
JavaCallArguments args(3); |
|
422 |
args.set_receiver(class_loader); |
|
423 |
args.push_oop(pkgname_string); |
|
424 |
args.push_oop(manifest); |
|
425 |
args.push_oop(url); |
|
426 |
JavaCalls::call_virtual(&result, app_classLoader_klass, |
|
427 |
vmSymbols::defineOrCheckPackage_name(), |
|
428 |
vmSymbols::defineOrCheckPackage_signature(), |
|
429 |
&args, |
|
430 |
CHECK); |
|
431 |
} |
|
432 |
} |
|
433 |
||
434 |
// Define Package for shared app/platform classes from named module |
|
435 |
void SystemDictionaryShared::define_shared_package(Symbol* class_name, |
|
436 |
Handle class_loader, |
|
437 |
ModuleEntry* mod_entry, |
|
438 |
TRAPS) { |
|
439 |
assert(mod_entry != NULL, "module_entry should not be NULL"); |
|
440 |
Handle module_handle(THREAD, mod_entry->module()); |
|
441 |
||
442 |
Handle pkg_name = get_package_name(class_name, CHECK); |
|
443 |
assert(pkg_name.not_null(), "Package should not be null for class in named module"); |
|
444 |
||
445 |
Klass* classLoader_klass; |
|
446 |
if (SystemDictionary::is_system_class_loader(class_loader())) { |
|
447 |
classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass(); |
|
448 |
} else { |
|
449 |
assert(SystemDictionary::is_platform_class_loader(class_loader()), "unexpected classloader"); |
|
450 |
classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass(); |
|
451 |
} |
|
452 |
||
453 |
JavaValue result(T_OBJECT); |
|
454 |
JavaCallArguments args(2); |
|
455 |
args.set_receiver(class_loader); |
|
456 |
args.push_oop(pkg_name); |
|
457 |
args.push_oop(module_handle); |
|
458 |
JavaCalls::call_virtual(&result, classLoader_klass, |
|
459 |
vmSymbols::definePackage_name(), |
|
460 |
vmSymbols::definePackage_signature(), |
|
461 |
&args, |
|
462 |
CHECK); |
|
463 |
} |
|
464 |
||
465 |
// Get the ProtectionDomain associated with the CodeSource from the classloader. |
|
466 |
Handle SystemDictionaryShared::get_protection_domain_from_classloader(Handle class_loader, |
|
467 |
Handle url, TRAPS) { |
|
468 |
// CodeSource cs = new CodeSource(url, null); |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
469 |
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
|
470 |
vmSymbols::url_code_signer_array_void_signature(), |
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
471 |
url, Handle(), CHECK_NH); |
48138 | 472 |
|
473 |
// protection_domain = SecureClassLoader.getProtectionDomain(cs); |
|
474 |
Klass* secureClassLoader_klass = SystemDictionary::SecureClassLoader_klass(); |
|
475 |
JavaValue obj_result(T_OBJECT); |
|
476 |
JavaCalls::call_virtual(&obj_result, class_loader, secureClassLoader_klass, |
|
477 |
vmSymbols::getProtectionDomain_name(), |
|
478 |
vmSymbols::getProtectionDomain_signature(), |
|
479 |
cs, CHECK_NH); |
|
480 |
return Handle(THREAD, (oop)obj_result.get_jobject()); |
|
481 |
} |
|
482 |
||
483 |
// Returns the ProtectionDomain associated with the JAR file identified by the url. |
|
484 |
Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader, |
|
485 |
int shared_path_index, |
|
486 |
Handle url, |
|
487 |
TRAPS) { |
|
488 |
Handle protection_domain; |
|
489 |
if (shared_protection_domain(shared_path_index) == NULL) { |
|
490 |
Handle pd = get_protection_domain_from_classloader(class_loader, url, THREAD); |
|
491 |
atomic_set_shared_protection_domain(shared_path_index, pd()); |
|
492 |
} |
|
493 |
||
494 |
// Acquire from the cache because if another thread beats the current one to |
|
495 |
// set the shared protection_domain and the atomic_set fails, the current thread |
|
496 |
// needs to get the updated protection_domain from the cache. |
|
497 |
protection_domain = Handle(THREAD, shared_protection_domain(shared_path_index)); |
|
498 |
assert(protection_domain.not_null(), "sanity"); |
|
499 |
return protection_domain; |
|
500 |
} |
|
501 |
||
502 |
// Returns the ProtectionDomain associated with the moduleEntry. |
|
503 |
Handle SystemDictionaryShared::get_shared_protection_domain(Handle class_loader, |
|
504 |
ModuleEntry* mod, TRAPS) { |
|
505 |
ClassLoaderData *loader_data = mod->loader_data(); |
|
506 |
Handle protection_domain; |
|
507 |
if (mod->shared_protection_domain() == NULL) { |
|
508 |
Symbol* location = mod->location(); |
|
509 |
if (location != NULL) { |
|
510 |
Handle url_string = java_lang_String::create_from_symbol( |
|
511 |
location, CHECK_(protection_domain)); |
|
512 |
JavaValue result(T_OBJECT); |
|
513 |
Klass* classLoaders_klass = |
|
514 |
SystemDictionary::jdk_internal_loader_ClassLoaders_klass(); |
|
50152
b5023063346d
8189140: SystemDictionaryShared::initialize() should be renamed to be more meaningful
iklam
parents:
50039
diff
changeset
|
515 |
JavaCalls::call_static(&result, classLoaders_klass, vmSymbols::toFileURL_name(), |
48138 | 516 |
vmSymbols::toFileURL_signature(), |
517 |
url_string, CHECK_(protection_domain)); |
|
518 |
Handle url = Handle(THREAD, (oop)result.get_jobject()); |
|
519 |
||
520 |
Handle pd = get_protection_domain_from_classloader(class_loader, url, THREAD); |
|
521 |
mod->set_shared_protection_domain(loader_data, pd); |
|
522 |
} |
|
523 |
} |
|
524 |
||
525 |
protection_domain = Handle(THREAD, mod->shared_protection_domain()); |
|
526 |
assert(protection_domain.not_null(), "sanity"); |
|
527 |
return protection_domain; |
|
528 |
} |
|
529 |
||
530 |
// Initializes the java.lang.Package and java.security.ProtectionDomain objects associated with |
|
531 |
// the given InstanceKlass. |
|
532 |
// Returns the ProtectionDomain for the InstanceKlass. |
|
533 |
Handle SystemDictionaryShared::init_security_info(Handle class_loader, InstanceKlass* ik, TRAPS) { |
|
534 |
Handle pd; |
|
535 |
||
536 |
if (ik != NULL) { |
|
537 |
int index = ik->shared_classpath_index(); |
|
538 |
assert(index >= 0, "Sanity"); |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
539 |
SharedClassPathEntry* ent = FileMapInfo::shared_path(index); |
48138 | 540 |
Symbol* class_name = ik->name(); |
541 |
||
542 |
if (ent->is_modules_image()) { |
|
543 |
// For shared app/platform classes originated from the run-time image: |
|
544 |
// The ProtectionDomains are cached in the corresponding ModuleEntries |
|
545 |
// for fast access by the VM. |
|
546 |
ResourceMark rm; |
|
547 |
ClassLoaderData *loader_data = |
|
548 |
ClassLoaderData::class_loader_data(class_loader()); |
|
549 |
PackageEntryTable* pkgEntryTable = loader_data->packages(); |
|
550 |
TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK_(pd)); |
|
551 |
if (pkg_name != NULL) { |
|
552 |
PackageEntry* pkg_entry = pkgEntryTable->lookup_only(pkg_name); |
|
553 |
if (pkg_entry != NULL) { |
|
554 |
ModuleEntry* mod_entry = pkg_entry->module(); |
|
555 |
pd = get_shared_protection_domain(class_loader, mod_entry, THREAD); |
|
556 |
define_shared_package(class_name, class_loader, mod_entry, CHECK_(pd)); |
|
557 |
} |
|
558 |
} |
|
559 |
} else { |
|
560 |
// For shared app/platform classes originated from JAR files on the class path: |
|
561 |
// Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length |
|
562 |
// 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
|
563 |
// FileMap::_shared_path_table in filemap.hpp for details). |
48138 | 564 |
// |
565 |
// If a shared InstanceKlass k is loaded from the class path, let |
|
566 |
// |
|
567 |
// index = k->shared_classpath_index(): |
|
568 |
// |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
569 |
// FileMap::_shared_path_table[index] identifies the JAR file that contains k. |
48138 | 570 |
// |
571 |
// k's protection domain is: |
|
572 |
// |
|
573 |
// ProtectionDomain pd = _shared_protection_domains[index]; |
|
574 |
// |
|
575 |
// and k's Package is initialized using |
|
576 |
// |
|
577 |
// manifest = _shared_jar_manifests[index]; |
|
578 |
// url = _shared_jar_urls[index]; |
|
579 |
// define_shared_package(class_name, class_loader, manifest, url, CHECK_(pd)); |
|
580 |
// |
|
581 |
// Note that if an element of these 3 _shared_xxx arrays is NULL, it will be initialized by |
|
582 |
// the corresponding SystemDictionaryShared::get_shared_xxx() function. |
|
583 |
Handle manifest = get_shared_jar_manifest(index, CHECK_(pd)); |
|
584 |
Handle url = get_shared_jar_url(index, CHECK_(pd)); |
|
585 |
define_shared_package(class_name, class_loader, manifest, url, CHECK_(pd)); |
|
586 |
pd = get_shared_protection_domain(class_loader, index, url, CHECK_(pd)); |
|
587 |
} |
|
588 |
} |
|
589 |
return pd; |
|
590 |
} |
|
591 |
||
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
592 |
bool SystemDictionaryShared::is_sharing_possible(ClassLoaderData* loader_data) { |
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
593 |
oop class_loader = loader_data->class_loader(); |
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
594 |
return (class_loader == NULL || |
49931 | 595 |
SystemDictionary::is_system_class_loader(class_loader) || |
596 |
SystemDictionary::is_platform_class_loader(class_loader)); |
|
49824
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
597 |
} |
e242740a92b8
8201556: Disallow reading oops in ClassLoaderData if unloading
coleenp
parents:
49739
diff
changeset
|
598 |
|
48138 | 599 |
// 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
|
600 |
// -Xbootclasspath/a path, the class path, and the module path. |
48138 | 601 |
// |
602 |
// Check if a shared class can be loaded by the specific classloader. Following |
|
603 |
// are the "visible" archived classes for different classloaders. |
|
604 |
// |
|
605 |
// NULL classloader: |
|
606 |
// - see SystemDictionary::is_shared_class_visible() |
|
607 |
// Platform classloader: |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
608 |
// - Module class from runtime image. ModuleEntry must be defined in the |
48138 | 609 |
// classloader. |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
610 |
// App classloader: |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
611 |
// - Module Class from runtime image and module path. ModuleEntry must be defined in the |
48138 | 612 |
// classloader. |
613 |
// - Class from -cp. The class must have no PackageEntry defined in any of the |
|
614 |
// boot/platform/app classloader, or must be in the unnamed module defined in the |
|
615 |
// AppClassLoader. |
|
616 |
bool SystemDictionaryShared::is_shared_class_visible_for_classloader( |
|
617 |
InstanceKlass* ik, |
|
618 |
Handle class_loader, |
|
619 |
const char* pkg_string, |
|
620 |
Symbol* pkg_name, |
|
621 |
PackageEntry* pkg_entry, |
|
622 |
ModuleEntry* mod_entry, |
|
623 |
TRAPS) { |
|
624 |
assert(class_loader.not_null(), "Class loader should not be NULL"); |
|
625 |
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
|
626 |
ResourceMark rm(THREAD); |
48138 | 627 |
|
628 |
int path_index = ik->shared_classpath_index(); |
|
629 |
SharedClassPathEntry* ent = |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
630 |
(SharedClassPathEntry*)FileMapInfo::shared_path(path_index); |
48138 | 631 |
|
632 |
if (SystemDictionary::is_platform_class_loader(class_loader())) { |
|
633 |
assert(ent != NULL, "shared class for PlatformClassLoader should have valid SharedClassPathEntry"); |
|
634 |
// The PlatformClassLoader can only load archived class originated from the |
|
635 |
// run-time image. The class' PackageEntry/ModuleEntry must be |
|
636 |
// defined by the PlatformClassLoader. |
|
637 |
if (mod_entry != NULL) { |
|
638 |
// PackageEntry/ModuleEntry is found in the classloader. Check if the |
|
639 |
// ModuleEntry's location agrees with the archived class' origination. |
|
640 |
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
|
641 |
return true; // Module class from the runtime image |
48138 | 642 |
} |
643 |
} |
|
644 |
} else if (SystemDictionary::is_system_class_loader(class_loader())) { |
|
645 |
assert(ent != NULL, "shared class for system loader should have valid SharedClassPathEntry"); |
|
646 |
if (pkg_string == NULL) { |
|
647 |
// The archived class is in the unnamed package. Currently, the boot image |
|
648 |
// does not contain any class in the unnamed package. |
|
649 |
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
|
650 |
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
|
651 |
assert(path_index < ClassLoaderExt::app_module_paths_start_index(), "invalid path_index"); |
48138 | 652 |
return true; |
653 |
} |
|
654 |
} else { |
|
655 |
// Check if this is from a PackageEntry/ModuleEntry defined in the AppClassloader. |
|
656 |
if (pkg_entry == NULL) { |
|
657 |
// It's not guaranteed that the class is from the classpath if the |
|
658 |
// PackageEntry cannot be found from the AppClassloader. Need to check |
|
659 |
// the boot and platform classloader as well. |
|
660 |
if (get_package_entry(pkg_name, ClassLoaderData::class_loader_data_or_null(SystemDictionary::java_platform_loader())) == NULL && |
|
661 |
get_package_entry(pkg_name, ClassLoaderData::the_null_class_loader_data()) == NULL) { |
|
662 |
// 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
|
663 |
// 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
|
664 |
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
|
665 |
path_index < ClassLoaderExt::app_module_paths_start_index()) { |
48138 | 666 |
return true; |
667 |
} |
|
668 |
} |
|
669 |
} else if (mod_entry != NULL) { |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
670 |
// 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
|
671 |
// 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
|
672 |
// a named module from a module path. |
48138 | 673 |
// 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
|
674 |
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
|
675 |
// shared module class from runtime image |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
676 |
return true; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
677 |
} 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
|
678 |
path_index < ClassLoaderExt::app_module_paths_start_index()) { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
679 |
// shared class from -cp |
48138 | 680 |
DEBUG_ONLY( \ |
681 |
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
|
682 |
assert(mod_entry == loader_data->unnamed_module(), "the unnamed module is not defined in the classloader");) |
48138 | 683 |
return true; |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
684 |
} else { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
685 |
if(!pkg_entry->in_unnamed_module() && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
686 |
(path_index >= ClassLoaderExt::app_module_paths_start_index())&& |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
687 |
(path_index < FileMapInfo::get_number_of_shared_paths()) && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
688 |
(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
|
689 |
// shared module class from module path |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
690 |
return true; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
691 |
} else { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49393
diff
changeset
|
692 |
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
|
693 |
} |
48138 | 694 |
} |
695 |
} |
|
696 |
} |
|
697 |
} else { |
|
698 |
// TEMP: if a shared class can be found by a custom loader, consider it visible now. |
|
699 |
// FIXME: is this actually correct? |
|
700 |
return true; |
|
701 |
} |
|
702 |
return false; |
|
703 |
} |
|
704 |
||
705 |
// The following stack shows how this code is reached: |
|
706 |
// |
|
707 |
// [0] SystemDictionaryShared::find_or_load_shared_class() |
|
708 |
// [1] JVM_FindLoadedClass |
|
709 |
// [2] java.lang.ClassLoader.findLoadedClass0() |
|
710 |
// [3] java.lang.ClassLoader.findLoadedClass() |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
711 |
// [4] jdk.internal.loader.BuiltinClassLoader.loadClassOrNull() |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
712 |
// [5] jdk.internal.loader.BuiltinClassLoader.loadClass() |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
713 |
// [6] jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(), or |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
714 |
// jdk.internal.loader.ClassLoaders$PlatformClassLoader.loadClass() |
48138 | 715 |
// |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
716 |
// 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
|
717 |
// jdk.internal.loader.ClassLoaders$PlatformClassLoader |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
718 |
// jdk.internal.loader.ClassLoaders$AppClassLoader |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
719 |
// 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
|
720 |
// |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
721 |
// [a] these two loaders use the BuiltinClassLoader.loadClassOrNull() to |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
722 |
// load the named class. |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
723 |
// [b] BuiltinClassLoader.loadClassOrNull() first calls findLoadedClass(name). |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
724 |
// [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
|
725 |
// shared_dictionary, we can perform further checks (see |
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
726 |
// 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
|
727 |
// was loaded by the same class loader during dump time. |
48138 | 728 |
// |
729 |
// Given these assumptions, we intercept the findLoadedClass() call to invoke |
|
730 |
// 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
|
731 |
// 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
|
732 |
// 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
|
733 |
// and avoid delegating to the parent loader. |
48138 | 734 |
// |
735 |
// NOTE: there's a lot of assumption about the Java code. If any of that change, this |
|
736 |
// needs to be redesigned. |
|
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
737 |
|
48138 | 738 |
InstanceKlass* SystemDictionaryShared::find_or_load_shared_class( |
739 |
Symbol* name, Handle class_loader, TRAPS) { |
|
740 |
InstanceKlass* k = NULL; |
|
49931 | 741 |
if (UseSharedSpaces) { |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49931
diff
changeset
|
742 |
if (!FileMapInfo::current_info()->header()->has_platform_or_app_classes()) { |
49931 | 743 |
return NULL; |
48138 | 744 |
} |
745 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
746 |
if (SystemDictionary::is_system_class_loader(class_loader()) || |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
747 |
SystemDictionary::is_platform_class_loader(class_loader())) { |
49931 | 748 |
// Fix for 4474172; see evaluation for more details |
749 |
class_loader = Handle( |
|
750 |
THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
|
751 |
ClassLoaderData *loader_data = register_loader(class_loader); |
|
752 |
Dictionary* dictionary = loader_data->dictionary(); |
|
753 |
||
754 |
unsigned int d_hash = dictionary->compute_hash(name); |
|
755 |
||
756 |
bool DoObjectLock = true; |
|
757 |
if (is_parallelCapable(class_loader)) { |
|
758 |
DoObjectLock = false; |
|
759 |
} |
|
48138 | 760 |
|
49931 | 761 |
// Make sure we are synchronized on the class loader before we proceed |
762 |
// |
|
763 |
// Note: currently, find_or_load_shared_class is called only from |
|
764 |
// JVM_FindLoadedClass and used for PlatformClassLoader and AppClassLoader, |
|
765 |
// which are parallel-capable loaders, so this lock is NOT taken. |
|
766 |
Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
|
767 |
check_loader_lock_contention(lockObject, THREAD); |
|
768 |
ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
|
769 |
||
770 |
{ |
|
771 |
MutexLocker mu(SystemDictionary_lock, THREAD); |
|
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
772 |
InstanceKlass* check = find_class(d_hash, name, dictionary); |
49931 | 773 |
if (check != NULL) { |
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
774 |
return check; |
49931 | 775 |
} |
776 |
} |
|
777 |
||
778 |
k = load_shared_class_for_builtin_loader(name, class_loader, THREAD); |
|
779 |
if (k != NULL) { |
|
780 |
define_instance_class(k, CHECK_NULL); |
|
48138 | 781 |
} |
782 |
} |
|
783 |
} |
|
784 |
return k; |
|
785 |
} |
|
786 |
||
787 |
InstanceKlass* SystemDictionaryShared::load_shared_class_for_builtin_loader( |
|
788 |
Symbol* class_name, Handle class_loader, TRAPS) { |
|
49931 | 789 |
assert(UseSharedSpaces, "must be"); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
790 |
InstanceKlass* ik = find_builtin_class(class_name); |
48138 | 791 |
|
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
792 |
if (ik != NULL) { |
48138 | 793 |
if ((ik->is_shared_app_class() && |
794 |
SystemDictionary::is_system_class_loader(class_loader())) || |
|
795 |
(ik->is_shared_platform_class() && |
|
796 |
SystemDictionary::is_platform_class_loader(class_loader()))) { |
|
797 |
Handle protection_domain = |
|
798 |
SystemDictionaryShared::init_security_info(class_loader, ik, CHECK_NULL); |
|
799 |
return load_shared_class(ik, class_loader, protection_domain, THREAD); |
|
800 |
} |
|
801 |
} |
|
802 |
return NULL; |
|
803 |
} |
|
804 |
||
805 |
void SystemDictionaryShared::oops_do(OopClosure* f) { |
|
806 |
f->do_oop((oop*)&_shared_protection_domains); |
|
807 |
f->do_oop((oop*)&_shared_jar_urls); |
|
808 |
f->do_oop((oop*)&_shared_jar_manifests); |
|
809 |
} |
|
810 |
||
811 |
void SystemDictionaryShared::allocate_shared_protection_domain_array(int size, TRAPS) { |
|
812 |
if (_shared_protection_domains == NULL) { |
|
813 |
_shared_protection_domains = oopFactory::new_objArray( |
|
814 |
SystemDictionary::ProtectionDomain_klass(), size, CHECK); |
|
815 |
} |
|
816 |
} |
|
817 |
||
818 |
void SystemDictionaryShared::allocate_shared_jar_url_array(int size, TRAPS) { |
|
819 |
if (_shared_jar_urls == NULL) { |
|
820 |
_shared_jar_urls = oopFactory::new_objArray( |
|
821 |
SystemDictionary::URL_klass(), size, CHECK); |
|
822 |
} |
|
823 |
} |
|
824 |
||
825 |
void SystemDictionaryShared::allocate_shared_jar_manifest_array(int size, TRAPS) { |
|
826 |
if (_shared_jar_manifests == NULL) { |
|
827 |
_shared_jar_manifests = oopFactory::new_objArray( |
|
828 |
SystemDictionary::Jar_Manifest_klass(), size, CHECK); |
|
829 |
} |
|
830 |
} |
|
831 |
||
832 |
void SystemDictionaryShared::allocate_shared_data_arrays(int size, TRAPS) { |
|
833 |
allocate_shared_protection_domain_array(size, CHECK); |
|
834 |
allocate_shared_jar_url_array(size, CHECK); |
|
835 |
allocate_shared_jar_manifest_array(size, CHECK); |
|
836 |
} |
|
837 |
||
49931 | 838 |
// This function is called for loading only UNREGISTERED classes |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
839 |
InstanceKlass* SystemDictionaryShared::lookup_from_stream(Symbol* class_name, |
48138 | 840 |
Handle class_loader, |
841 |
Handle protection_domain, |
|
842 |
const ClassFileStream* cfs, |
|
843 |
TRAPS) { |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
844 |
if (!UseSharedSpaces) { |
48138 | 845 |
return NULL; |
846 |
} |
|
847 |
if (class_name == NULL) { // don't do this for anonymous classes |
|
848 |
return NULL; |
|
849 |
} |
|
850 |
if (class_loader.is_null() || |
|
851 |
SystemDictionary::is_system_class_loader(class_loader()) || |
|
852 |
SystemDictionary::is_platform_class_loader(class_loader())) { |
|
853 |
// Do nothing for the BUILTIN loaders. |
|
854 |
return NULL; |
|
855 |
} |
|
856 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
857 |
const RunTimeSharedClassInfo* record = find_record(&_unregistered_dictionary, class_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
858 |
if (record == NULL) { |
48138 | 859 |
return NULL; |
860 |
} |
|
861 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
862 |
int clsfile_size = cfs->length(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
863 |
int clsfile_crc32 = ClassLoader::crc32(0, (const char*)cfs->buffer(), cfs->length()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
864 |
if (!record->matches(clsfile_size, clsfile_crc32)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
865 |
return NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
866 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
867 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
868 |
return acquire_class_for_current_thread(record->_klass, class_loader, |
48138 | 869 |
protection_domain, THREAD); |
870 |
} |
|
871 |
||
872 |
InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread( |
|
873 |
InstanceKlass *ik, |
|
874 |
Handle class_loader, |
|
875 |
Handle protection_domain, |
|
876 |
TRAPS) { |
|
877 |
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader()); |
|
878 |
||
879 |
{ |
|
880 |
MutexLocker mu(SharedDictionary_lock, THREAD); |
|
881 |
if (ik->class_loader_data() != NULL) { |
|
882 |
// ik is already loaded (by this loader or by a different loader) |
|
883 |
// or ik is being loaded by a different thread (by this loader or by a different loader) |
|
884 |
return NULL; |
|
885 |
} |
|
886 |
||
887 |
// No other thread has acquired this yet, so give it to *this thread* |
|
888 |
ik->set_class_loader_data(loader_data); |
|
889 |
} |
|
890 |
||
891 |
// No longer holding SharedDictionary_lock |
|
892 |
// No need to lock, as <ik> can be held only by a single thread. |
|
893 |
loader_data->add_class(ik); |
|
894 |
||
895 |
// Load and check super/interfaces, restore unsharable info |
|
896 |
InstanceKlass* shared_klass = load_shared_class(ik, class_loader, protection_domain, THREAD); |
|
897 |
if (shared_klass == NULL || HAS_PENDING_EXCEPTION) { |
|
898 |
// TODO: clean up <ik> so it can be used again |
|
899 |
return NULL; |
|
900 |
} |
|
901 |
||
902 |
return shared_klass; |
|
903 |
} |
|
904 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
905 |
static ResourceHashtable< |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
906 |
Symbol*, bool, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
907 |
primitive_hash<Symbol*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
908 |
primitive_equals<Symbol*>, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
909 |
6661, // prime number |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
910 |
ResourceObj::C_HEAP> _loaded_unregistered_classes; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
911 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
912 |
bool SystemDictionaryShared::add_unregistered_class(InstanceKlass* k, TRAPS) { |
48138 | 913 |
assert(DumpSharedSpaces, "only when dumping"); |
914 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
915 |
Symbol* name = k->name(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
916 |
if (_loaded_unregistered_classes.get(name) != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
917 |
// We don't allow duplicated unregistered classes of the same name. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
918 |
return false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
919 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
920 |
bool isnew = _loaded_unregistered_classes.put(name, true); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
921 |
assert(isnew, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
922 |
MutexLocker mu_r(Compile_lock, THREAD); // add_to_hierarchy asserts this. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
923 |
SystemDictionary::add_to_hierarchy(k, CHECK_0); |
48138 | 924 |
return true; |
925 |
} |
|
926 |
} |
|
927 |
||
928 |
// This function is called to resolve the super/interfaces of shared classes for |
|
929 |
// non-built-in loaders. E.g., ChildClass in the below example |
|
930 |
// where "super:" (and optionally "interface:") have been specified. |
|
931 |
// |
|
932 |
// java/lang/Object id: 0 |
|
933 |
// Interface id: 2 super: 0 source: cust.jar |
|
934 |
// 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
|
935 |
InstanceKlass* SystemDictionaryShared::dump_time_resolve_super_or_fail( |
48138 | 936 |
Symbol* child_name, Symbol* class_name, Handle class_loader, |
937 |
Handle protection_domain, bool is_superclass, TRAPS) { |
|
938 |
||
939 |
assert(DumpSharedSpaces, "only when dumping"); |
|
940 |
||
941 |
ClassListParser* parser = ClassListParser::instance(); |
|
942 |
if (parser == NULL) { |
|
943 |
// We're still loading the well-known classes, before the ClassListParser is created. |
|
944 |
return NULL; |
|
945 |
} |
|
946 |
if (child_name->equals(parser->current_class_name())) { |
|
947 |
// When this function is called, all the numbered super and interface types |
|
948 |
// must have already been loaded. Hence this function is never recursively called. |
|
949 |
if (is_superclass) { |
|
950 |
return parser->lookup_super_for_current_class(class_name); |
|
951 |
} else { |
|
952 |
return parser->lookup_interface_for_current_class(class_name); |
|
953 |
} |
|
954 |
} else { |
|
955 |
// The VM is not trying to resolve a super type of parser->current_class_name(). |
|
956 |
// Instead, it's resolving an error class (because parser->current_class_name() has |
|
957 |
// failed parsing or verification). Don't do anything here. |
|
958 |
return NULL; |
|
959 |
} |
|
960 |
} |
|
961 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
962 |
DumpTimeSharedClassInfo* SystemDictionaryShared::find_or_allocate_info_for(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
963 |
if (_dumptime_table == NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
964 |
_dumptime_table = new (ResourceObj::C_HEAP, mtClass)DumpTimeSharedClassTable(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
965 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
966 |
return _dumptime_table->find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
967 |
} |
48138 | 968 |
|
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
969 |
void SystemDictionaryShared::set_shared_class_misc_info(InstanceKlass* k, ClassFileStream* cfs) { |
48138 | 970 |
assert(DumpSharedSpaces, "only when dumping"); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
971 |
assert(!is_builtin(k), "must be unregistered class"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
972 |
DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
973 |
info->_clsfile_size = cfs->length(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
974 |
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
|
975 |
} |
48138 | 976 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
977 |
void SystemDictionaryShared::init_dumptime_info(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
978 |
(void)find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
979 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
980 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
981 |
void SystemDictionaryShared::remove_dumptime_info(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
982 |
_dumptime_table->remove(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
983 |
} |
48138 | 984 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
985 |
bool SystemDictionaryShared::is_jfr_event_class(InstanceKlass *k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
986 |
while (k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
987 |
if (k->name()->equals("jdk/internal/event/Event")) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
988 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
989 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
990 |
k = k->java_super(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
991 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
992 |
return false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
993 |
} |
48138 | 994 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
995 |
void SystemDictionaryShared::warn_excluded(InstanceKlass* k, const char* reason) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
996 |
ResourceMark rm; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
997 |
log_warning(cds)("Skipping %s: %s", k->name()->as_C_string(), reason); |
48138 | 998 |
} |
999 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1000 |
bool SystemDictionaryShared::should_be_excluded(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1001 |
if (k->class_loader_data()->is_unsafe_anonymous()) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1002 |
return true; // unsafe anonymous classes are not archived, skip |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1003 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1004 |
if (k->is_in_error_state()) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1005 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1006 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1007 |
if (k->shared_classpath_index() < 0 && is_builtin(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1008 |
// 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
|
1009 |
// agent during dump time). |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1010 |
warn_excluded(k, "Unsupported location"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1011 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1012 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1013 |
if (k->signers() != NULL) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1014 |
// We cannot include signed classes in the archive because the certificates |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1015 |
// used during dump time may be different than those used during |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1016 |
// runtime (due to expiration, etc). |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1017 |
warn_excluded(k, "Signed JAR"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1018 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1019 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1020 |
if (is_jfr_event_class(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1021 |
// We cannot include JFR event classes because they need runtime-specific |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1022 |
// instrumentation in order to work with -XX:FlightRecorderOptions=retransform=false. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1023 |
// 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
|
1024 |
// support them and make CDS more complicated. |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1025 |
warn_excluded(k, "JFR event class"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1026 |
return true; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1027 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1028 |
return false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1029 |
} |
48138 | 1030 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1031 |
// k is a class before relocating by ArchiveCompactor |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1032 |
void SystemDictionaryShared::validate_before_archiving(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1033 |
ResourceMark rm; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1034 |
const char* name = k->name()->as_C_string(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1035 |
DumpTimeSharedClassInfo* info = _dumptime_table->get(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1036 |
guarantee(info != NULL, "Class %s must be entered into _dumptime_table", name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1037 |
guarantee(!info->_excluded, "Should not attempt to archive excluded class %s", name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1038 |
if (is_builtin(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1039 |
guarantee(k->loader_type() != 0, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1040 |
"Class loader type must be set for BUILTIN class %s", name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1041 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1042 |
guarantee(k->loader_type() == 0, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1043 |
"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
|
1044 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1045 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1046 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1047 |
class ExcludeDumpTimeSharedClasses : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1048 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1049 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1050 |
if (SystemDictionaryShared::should_be_excluded(k)) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1051 |
info._excluded = true; |
48138 | 1052 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1053 |
return true; // keep on iterating |
48138 | 1054 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1055 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1056 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1057 |
void SystemDictionaryShared::check_excluded_classes() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1058 |
ExcludeDumpTimeSharedClasses excl; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1059 |
_dumptime_table->iterate(&excl); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1060 |
DEBUG_ONLY(_checked_excluded_classes = true;) |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1061 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1062 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1063 |
bool SystemDictionaryShared::is_excluded_class(InstanceKlass* k) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1064 |
assert(_checked_excluded_classes, "sanity"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1065 |
assert(DumpSharedSpaces, "only when dumping"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1066 |
return find_or_allocate_info_for(k)->_excluded; |
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 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1069 |
class IterateDumpTimeSharedClassTable : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1070 |
MetaspaceClosure *_it; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1071 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1072 |
IterateDumpTimeSharedClassTable(MetaspaceClosure* it) : _it(it) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1073 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1074 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1075 |
if (!info._excluded) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1076 |
info.metaspace_pointers_do(_it); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1077 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1078 |
return true; // keep on iterating |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1079 |
} |
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 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1082 |
void SystemDictionaryShared::dumptime_classes_do(class MetaspaceClosure* it) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1083 |
IterateDumpTimeSharedClassTable iter(it); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1084 |
_dumptime_table->iterate(&iter); |
48138 | 1085 |
} |
1086 |
||
51329
9c68699bebe5
8208999: Some use of Klass* should be replaced by InstanceKlass*
iklam
parents:
51070
diff
changeset
|
1087 |
bool SystemDictionaryShared::add_verification_constraint(InstanceKlass* k, Symbol* name, |
48138 | 1088 |
Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) { |
1089 |
assert(DumpSharedSpaces, "called at dump time only"); |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1090 |
DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1091 |
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
|
1092 |
from_is_array, from_is_object); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1093 |
if (is_builtin(k)) { |
48138 | 1094 |
// For builtin class loaders, we can try to complete the verification check at dump time, |
1095 |
// because we can resolve all the constraint classes. |
|
1096 |
return false; |
|
1097 |
} else { |
|
1098 |
// For non-builtin class loaders, we cannot complete the verification check at dump time, |
|
1099 |
// because at dump time we don't know how to resolve classes for such loaders. |
|
1100 |
return true; |
|
1101 |
} |
|
1102 |
} |
|
1103 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1104 |
void DumpTimeSharedClassInfo::add_verification_constraint(InstanceKlass* k, Symbol* name, |
48138 | 1105 |
Symbol* from_name, bool from_field_is_protected, bool from_is_array, bool from_is_object) { |
1106 |
if (_verifier_constraints == NULL) { |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1107 |
_verifier_constraints = new(ResourceObj::C_HEAP, mtClass) GrowableArray<DTConstraint>(4, true, mtClass); |
48138 | 1108 |
} |
1109 |
if (_verifier_constraint_flags == NULL) { |
|
1110 |
_verifier_constraint_flags = new(ResourceObj::C_HEAP, mtClass) GrowableArray<char>(4, true, mtClass); |
|
1111 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1112 |
GrowableArray<DTConstraint>* vc_array = _verifier_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1113 |
for (int i = 0; i < vc_array->length(); i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1114 |
DTConstraint* p = vc_array->adr_at(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1115 |
if (name == p->_name && from_name == p->_from_name) { |
48138 | 1116 |
return; |
1117 |
} |
|
1118 |
} |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1119 |
DTConstraint cons(name, from_name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1120 |
vc_array->append(cons); |
48138 | 1121 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1122 |
GrowableArray<char>* vcflags_array = _verifier_constraint_flags; |
48138 | 1123 |
char c = 0; |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1124 |
c |= from_field_is_protected ? SystemDictionaryShared::FROM_FIELD_IS_PROTECTED : 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1125 |
c |= from_is_array ? SystemDictionaryShared::FROM_IS_ARRAY : 0; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1126 |
c |= from_is_object ? SystemDictionaryShared::FROM_IS_OBJECT : 0; |
48138 | 1127 |
vcflags_array->append(c); |
1128 |
||
1129 |
if (log_is_enabled(Trace, cds, verification)) { |
|
1130 |
ResourceMark rm; |
|
1131 |
log_trace(cds, verification)("add_verification_constraint: %s: %s must be subclass of %s", |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1132 |
k->external_name(), from_name->as_klass_external_name(), |
48138 | 1133 |
name->as_klass_external_name()); |
1134 |
} |
|
1135 |
} |
|
1136 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1137 |
void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass, |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1138 |
TRAPS) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1139 |
assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1140 |
RunTimeSharedClassInfo* record = RunTimeSharedClassInfo::get_for(klass); |
48138 | 1141 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1142 |
int length = record->_num_constraints; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1143 |
if (length > 0) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1144 |
for (int i = 0; i < length; i++) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1145 |
Symbol* name = record->get_constraint_name(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1146 |
Symbol* from_name = record->get_constraint_from_name(i); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1147 |
char c = record->get_constraint_flag(i); |
48138 | 1148 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1149 |
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
|
1150 |
bool from_is_array = (c & SystemDictionaryShared::FROM_IS_ARRAY) ? true : false; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1151 |
bool from_is_object = (c & SystemDictionaryShared::FROM_IS_OBJECT) ? true : false; |
48138 | 1152 |
|
1153 |
bool ok = VerificationType::resolve_and_check_assignability(klass, name, |
|
1154 |
from_name, from_field_is_protected, from_is_array, from_is_object, CHECK); |
|
1155 |
if (!ok) { |
|
1156 |
ResourceMark rm(THREAD); |
|
1157 |
stringStream ss; |
|
1158 |
||
1159 |
ss.print_cr("Bad type on operand stack"); |
|
1160 |
ss.print_cr("Exception Details:"); |
|
1161 |
ss.print_cr(" Location:\n %s", klass->name()->as_C_string()); |
|
1162 |
ss.print_cr(" Reason:\n Type '%s' is not assignable to '%s'", |
|
1163 |
from_name->as_quoted_ascii(), name->as_quoted_ascii()); |
|
1164 |
THROW_MSG(vmSymbols::java_lang_VerifyError(), ss.as_string()); |
|
1165 |
} |
|
1166 |
} |
|
1167 |
} |
|
1168 |
} |
|
1169 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1170 |
class CopySharedClassInfoToArchive : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1171 |
CompactHashtableWriter* _writer; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1172 |
bool _is_builtin; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1173 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1174 |
CopySharedClassInfoToArchive(CompactHashtableWriter* writer, bool is_builtin) |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1175 |
: _writer(writer), _is_builtin(is_builtin) {} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1176 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1177 |
bool do_entry(InstanceKlass* k, DumpTimeSharedClassInfo& info) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1178 |
if (!info._excluded && info.is_builtin() == _is_builtin) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1179 |
size_t byte_size = RunTimeSharedClassInfo::byte_size(info._klass, info.num_constraints()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1180 |
RunTimeSharedClassInfo* record = |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1181 |
(RunTimeSharedClassInfo*)MetaspaceShared::read_only_space_alloc(byte_size); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1182 |
record->init(info); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1183 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1184 |
unsigned int hash = primitive_hash<Symbol*>(info._klass->name()); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1185 |
_writer->add(hash, MetaspaceShared::object_delta_u4(record)); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1186 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1187 |
// Save this for quick runtime lookup of InstanceKlass* -> RunTimeSharedClassInfo* |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1188 |
RunTimeSharedClassInfo::set_for(info._klass, record); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1189 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1190 |
return true; // keep on iterating |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1191 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1192 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1193 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1194 |
void SystemDictionaryShared::write_dictionary(RunTimeSharedDictionary* dictionary, bool is_builtin) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1195 |
CompactHashtableStats stats; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1196 |
dictionary->reset(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1197 |
int num_buckets = CompactHashtableWriter::default_num_buckets(_dumptime_table->count_of(is_builtin)); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1198 |
CompactHashtableWriter writer(num_buckets, &stats); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1199 |
CopySharedClassInfoToArchive copy(&writer, is_builtin); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1200 |
_dumptime_table->iterate(©); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1201 |
writer.dump(dictionary, is_builtin ? "builtin dictionary" : "unregistered dictionary"); |
48138 | 1202 |
} |
1203 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1204 |
void SystemDictionaryShared::write_to_archive() { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1205 |
_dumptime_table->update_counts(); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1206 |
write_dictionary(&_builtin_dictionary, true); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1207 |
write_dictionary(&_unregistered_dictionary, false); |
48138 | 1208 |
} |
1209 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1210 |
void SystemDictionaryShared::serialize_dictionary_headers(SerializeClosure* soc) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1211 |
_builtin_dictionary.serialize_header(soc); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1212 |
_unregistered_dictionary.serialize_header(soc); |
48138 | 1213 |
} |
1214 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1215 |
const RunTimeSharedClassInfo* |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1216 |
SystemDictionaryShared::find_record(RunTimeSharedDictionary* dict, Symbol* name) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1217 |
if (UseSharedSpaces) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1218 |
unsigned int hash = primitive_hash<Symbol*>(name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1219 |
return dict->lookup(name, hash, 0); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1220 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1221 |
return NULL; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1222 |
} |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1223 |
} |
48138 | 1224 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1225 |
InstanceKlass* SystemDictionaryShared::find_builtin_class(Symbol* name) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1226 |
const RunTimeSharedClassInfo* record = find_record(&_builtin_dictionary, name); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1227 |
if (record) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1228 |
return record->_klass; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1229 |
} else { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1230 |
return NULL; |
48138 | 1231 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1232 |
} |
48138 | 1233 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1234 |
void SystemDictionaryShared::update_shared_entry(InstanceKlass* k, int id) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1235 |
assert(DumpSharedSpaces, "supported only when dumping"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1236 |
DumpTimeSharedClassInfo* info = find_or_allocate_info_for(k); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1237 |
info->_id = id; |
48138 | 1238 |
} |
1239 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1240 |
class SharedDictionaryPrinter : StackObj { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1241 |
outputStream* _st; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1242 |
int _index; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1243 |
public: |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1244 |
SharedDictionaryPrinter(outputStream* st) : _st(st), _index(0) {} |
48138 | 1245 |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1246 |
void do_value(const RunTimeSharedClassInfo* record) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1247 |
ResourceMark rm; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1248 |
_st->print_cr("%4d: %s", (_index++), record->_klass->external_name()); |
48138 | 1249 |
} |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1250 |
}; |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1251 |
|
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1252 |
void SystemDictionaryShared::print_on(outputStream* st) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1253 |
if (UseSharedSpaces) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1254 |
st->print_cr("Shared Dictionary"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1255 |
SharedDictionaryPrinter p(st); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1256 |
_builtin_dictionary.iterate(&p); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1257 |
_unregistered_dictionary.iterate(&p); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1258 |
} |
48138 | 1259 |
} |
1260 |
||
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1261 |
void SystemDictionaryShared::print_table_statistics(outputStream* st) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1262 |
if (UseSharedSpaces) { |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1263 |
_builtin_dictionary.print_table_statistics(st, "Builtin Shared Dictionary"); |
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52468
diff
changeset
|
1264 |
_unregistered_dictionary.print_table_statistics(st, "Unregistered Shared Dictionary"); |
48138 | 1265 |
} |
1266 |
} |