author | lfoltan |
Mon, 21 Oct 2019 13:13:16 -0400 | |
changeset 58722 | cba8afa5cfed |
parent 58447 | 319173c62caa |
permissions | -rw-r--r-- |
34666 | 1 |
/* |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
34666 | 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/classFileParser.hpp" |
|
27 |
#include "classfile/classFileStream.hpp" |
|
41182 | 28 |
#include "classfile/classLoader.hpp" |
34666 | 29 |
#include "classfile/classLoaderData.hpp" |
41182 | 30 |
#include "classfile/classLoaderData.inline.hpp" |
34666 | 31 |
#include "classfile/klassFactory.hpp" |
50039
9fec54fe663d
8197954: Remove unnecessary intermediary APIs from AppCDS implementation
iklam
parents:
49739
diff
changeset
|
32 |
#include "memory/filemap.hpp" |
41182 | 33 |
#include "memory/metaspaceShared.hpp" |
34666 | 34 |
#include "memory/resourceArea.hpp" |
35 |
#include "prims/jvmtiEnvBase.hpp" |
|
41182 | 36 |
#include "prims/jvmtiRedefineClasses.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
47991
diff
changeset
|
37 |
#include "runtime/handles.inline.hpp" |
50113 | 38 |
#include "utilities/macros.hpp" |
39 |
#if INCLUDE_JFR |
|
40 |
#include "jfr/support/jfrKlassExtension.hpp" |
|
41 |
#endif |
|
42 |
||
34666 | 43 |
|
41182 | 44 |
// called during initial loading of a shared class |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
45 |
InstanceKlass* KlassFactory::check_shared_class_file_load_hook( |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
46 |
InstanceKlass* ik, |
41182 | 47 |
Symbol* class_name, |
48 |
Handle class_loader, |
|
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
49 |
Handle protection_domain, |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
50 |
const ClassFileStream *cfs, |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
51 |
TRAPS) { |
41182 | 52 |
#if INCLUDE_CDS && INCLUDE_JVMTI |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
53 |
assert(ik != NULL, "sanity"); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
54 |
assert(ik->is_shared(), "expecting a shared class"); |
41182 | 55 |
if (JvmtiExport::should_post_class_file_load_hook()) { |
56 |
assert(THREAD->is_Java_thread(), "must be JavaThread"); |
|
57 |
||
58 |
// Post the CFLH |
|
59 |
JvmtiCachedClassFileData* cached_class_file = NULL; |
|
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
60 |
if (cfs == NULL) { |
54340
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53884
diff
changeset
|
61 |
cfs = FileMapInfo::open_stream_for_jvmti(ik, class_loader, CHECK_NULL); |
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
62 |
} |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
63 |
unsigned char* ptr = (unsigned char*)cfs->buffer(); |
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
64 |
unsigned char* end_ptr = ptr + cfs->length(); |
41182 | 65 |
unsigned char* old_ptr = ptr; |
66 |
JvmtiExport::post_class_file_load_hook(class_name, |
|
67 |
class_loader, |
|
68 |
protection_domain, |
|
69 |
&ptr, |
|
70 |
&end_ptr, |
|
71 |
&cached_class_file); |
|
72 |
if (old_ptr != ptr) { |
|
73 |
// JVMTI agent has modified class file data. |
|
74 |
// Set new class file stream using JVMTI agent modified class file data. |
|
75 |
ClassLoaderData* loader_data = |
|
76 |
ClassLoaderData::class_loader_data(class_loader()); |
|
77 |
int path_index = ik->shared_classpath_index(); |
|
78 |
ClassFileStream* stream = new ClassFileStream(ptr, |
|
79 |
end_ptr - ptr, |
|
53884
1a7b57d02107
8218751: Do not store original classfiles inside the CDS archive
iklam
parents:
52692
diff
changeset
|
80 |
cfs->source(), |
41182 | 81 |
ClassFileStream::verify); |
82 |
ClassFileParser parser(stream, |
|
83 |
class_name, |
|
84 |
loader_data, |
|
85 |
protection_domain, |
|
86 |
NULL, |
|
87 |
NULL, |
|
88 |
ClassFileParser::BROADCAST, // publicity level |
|
89 |
CHECK_NULL); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
90 |
InstanceKlass* new_ik = parser.create_instance_klass(true /* changed_by_loadhook */, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
91 |
CHECK_NULL); |
41182 | 92 |
if (cached_class_file != NULL) { |
93 |
new_ik->set_cached_class_file(cached_class_file); |
|
94 |
} |
|
95 |
||
96 |
if (class_loader.is_null()) { |
|
97 |
ResourceMark rm; |
|
98 |
ClassLoader::add_package(class_name->as_C_string(), path_index, THREAD); |
|
99 |
} |
|
100 |
||
101 |
return new_ik; |
|
102 |
} |
|
103 |
} |
|
104 |
#endif |
|
105 |
||
106 |
return NULL; |
|
107 |
} |
|
108 |
||
109 |
||
40658
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
110 |
static ClassFileStream* check_class_file_load_hook(ClassFileStream* stream, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
111 |
Symbol* name, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
112 |
ClassLoaderData* loader_data, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
113 |
Handle protection_domain, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
114 |
JvmtiCachedClassFileData** cached_class_file, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
115 |
TRAPS) { |
34666 | 116 |
|
117 |
assert(stream != NULL, "invariant"); |
|
118 |
||
119 |
if (JvmtiExport::should_post_class_file_load_hook()) { |
|
120 |
assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
|
121 |
const JavaThread* jt = (JavaThread*)THREAD; |
|
122 |
||
123 |
Handle class_loader(THREAD, loader_data->class_loader()); |
|
124 |
||
125 |
// Get the cached class file bytes (if any) from the class that |
|
126 |
// is being redefined or retransformed. We use jvmti_thread_state() |
|
127 |
// instead of JvmtiThreadState::state_for(jt) so we don't allocate |
|
128 |
// a JvmtiThreadState any earlier than necessary. This will help |
|
129 |
// avoid the bug described by 7126851. |
|
130 |
||
131 |
JvmtiThreadState* state = jt->jvmti_thread_state(); |
|
132 |
||
133 |
if (state != NULL) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
134 |
Klass* k = state->get_class_being_redefined(); |
34666 | 135 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
136 |
if (k != NULL) { |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
137 |
InstanceKlass* class_being_redefined = InstanceKlass::cast(k); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
138 |
*cached_class_file = class_being_redefined->get_cached_class_file(); |
34666 | 139 |
} |
140 |
} |
|
141 |
||
142 |
unsigned char* ptr = const_cast<unsigned char*>(stream->buffer()); |
|
143 |
unsigned char* end_ptr = ptr + stream->length(); |
|
144 |
||
145 |
JvmtiExport::post_class_file_load_hook(name, |
|
146 |
class_loader, |
|
147 |
protection_domain, |
|
148 |
&ptr, |
|
149 |
&end_ptr, |
|
150 |
cached_class_file); |
|
151 |
||
152 |
if (ptr != stream->buffer()) { |
|
153 |
// JVMTI agent has modified class file data. |
|
154 |
// Set new class file stream using JVMTI agent modified class file data. |
|
155 |
stream = new ClassFileStream(ptr, |
|
156 |
end_ptr - ptr, |
|
157 |
stream->source(), |
|
158 |
stream->need_verify()); |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
return stream; |
|
163 |
} |
|
164 |
||
165 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
166 |
InstanceKlass* KlassFactory::create_from_stream(ClassFileStream* stream, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
167 |
Symbol* name, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
168 |
ClassLoaderData* loader_data, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
169 |
Handle protection_domain, |
51444
3e5d28e6de32
8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents:
50785
diff
changeset
|
170 |
const InstanceKlass* unsafe_anonymous_host, |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
171 |
GrowableArray<Handle>* cp_patches, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
172 |
TRAPS) { |
34666 | 173 |
assert(stream != NULL, "invariant"); |
174 |
assert(loader_data != NULL, "invariant"); |
|
175 |
assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
|
176 |
||
177 |
ResourceMark rm; |
|
178 |
HandleMark hm; |
|
179 |
||
180 |
JvmtiCachedClassFileData* cached_class_file = NULL; |
|
181 |
||
36508 | 182 |
ClassFileStream* old_stream = stream; |
183 |
||
50785
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50113
diff
changeset
|
184 |
// increment counter |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50113
diff
changeset
|
185 |
THREAD->statistical_info().incr_define_class_count(); |
d1b24f2ceca5
8200720: Print additional information in thread dump (times, allocated bytes etc.)
ghaug
parents:
50113
diff
changeset
|
186 |
|
40658
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
187 |
// Skip this processing for VM anonymous classes |
51444
3e5d28e6de32
8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents:
50785
diff
changeset
|
188 |
if (unsafe_anonymous_host == NULL) { |
40658
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
189 |
stream = check_class_file_load_hook(stream, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
190 |
name, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
191 |
loader_data, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
192 |
protection_domain, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
193 |
&cached_class_file, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
194 |
CHECK_NULL); |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
195 |
} |
34666 | 196 |
|
197 |
ClassFileParser parser(stream, |
|
198 |
name, |
|
199 |
loader_data, |
|
200 |
protection_domain, |
|
51444
3e5d28e6de32
8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents:
50785
diff
changeset
|
201 |
unsafe_anonymous_host, |
34666 | 202 |
cp_patches, |
203 |
ClassFileParser::BROADCAST, // publicity level |
|
204 |
CHECK_NULL); |
|
205 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
206 |
InstanceKlass* result = parser.create_instance_klass(old_stream != stream, CHECK_NULL); |
36508 | 207 |
assert(result == parser.create_instance_klass(old_stream != stream, THREAD), "invariant"); |
34666 | 208 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
209 |
if (result == NULL) { |
34666 | 210 |
return NULL; |
211 |
} |
|
212 |
||
213 |
if (cached_class_file != NULL) { |
|
214 |
// JVMTI: we have an InstanceKlass now, tell it about the cached bytes |
|
215 |
result->set_cached_class_file(cached_class_file); |
|
216 |
} |
|
217 |
||
50113 | 218 |
JFR_ONLY(ON_KLASS_CREATION(result, parser, THREAD);) |
36386
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
219 |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
220 |
#if INCLUDE_CDS |
58447
319173c62caa
8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents:
54927
diff
changeset
|
221 |
if (Arguments::is_dumping_archive()) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49480
diff
changeset
|
222 |
ClassLoader::record_result(result, stream, THREAD); |
41182 | 223 |
} |
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
224 |
#endif // INCLUDE_CDS |
41182 | 225 |
|
34666 | 226 |
return result; |
227 |
} |