author | iklam |
Thu, 26 Apr 2018 13:40:58 -0700 | |
changeset 50039 | 9fec54fe663d |
parent 49739 | 00805b129186 |
child 50113 | caf115bb98ad |
permissions | -rw-r--r-- |
34666 | 1 |
/* |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
47991
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, 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" |
36386
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
38 |
#include "trace/traceMacros.hpp" |
34666 | 39 |
|
41182 | 40 |
// called during initial loading of a shared class |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
41 |
InstanceKlass* KlassFactory::check_shared_class_file_load_hook( |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
42 |
InstanceKlass* ik, |
41182 | 43 |
Symbol* class_name, |
44 |
Handle class_loader, |
|
45 |
Handle protection_domain, TRAPS) { |
|
46 |
#if INCLUDE_CDS && INCLUDE_JVMTI |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
47 |
assert(ik != NULL, "sanity"); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
48 |
assert(ik->is_shared(), "expecting a shared class"); |
41182 | 49 |
|
50 |
if (JvmtiExport::should_post_class_file_load_hook()) { |
|
51 |
assert(THREAD->is_Java_thread(), "must be JavaThread"); |
|
52 |
||
53 |
// Post the CFLH |
|
54 |
JvmtiCachedClassFileData* cached_class_file = NULL; |
|
55 |
JvmtiCachedClassFileData* archived_class_data = ik->get_archived_class_data(); |
|
56 |
assert(archived_class_data != NULL, "shared class has no archived class data"); |
|
57 |
unsigned char* ptr = |
|
58 |
VM_RedefineClasses::get_cached_class_file_bytes(archived_class_data); |
|
59 |
unsigned char* end_ptr = |
|
60 |
ptr + VM_RedefineClasses::get_cached_class_file_len(archived_class_data); |
|
61 |
unsigned char* old_ptr = ptr; |
|
62 |
JvmtiExport::post_class_file_load_hook(class_name, |
|
63 |
class_loader, |
|
64 |
protection_domain, |
|
65 |
&ptr, |
|
66 |
&end_ptr, |
|
67 |
&cached_class_file); |
|
68 |
if (old_ptr != ptr) { |
|
69 |
// JVMTI agent has modified class file data. |
|
70 |
// Set new class file stream using JVMTI agent modified class file data. |
|
71 |
ClassLoaderData* loader_data = |
|
72 |
ClassLoaderData::class_loader_data(class_loader()); |
|
73 |
int path_index = ik->shared_classpath_index(); |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
74 |
const char* pathname; |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
75 |
if (path_index < 0) { |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
76 |
// shared classes loaded by user defined class loader |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
77 |
// do not have shared_classpath_index |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
78 |
ModuleEntry* mod_entry = ik->module(); |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
79 |
if (mod_entry != NULL && (mod_entry->location() != NULL)) { |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
80 |
ResourceMark rm; |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
81 |
pathname = (const char*)(mod_entry->location()->as_C_string()); |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
82 |
} else { |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
83 |
pathname = ""; |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
84 |
} |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
85 |
} else { |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
86 |
SharedClassPathEntry* ent = |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49480
diff
changeset
|
87 |
(SharedClassPathEntry*)FileMapInfo::shared_path(path_index); |
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
88 |
pathname = ent == NULL ? NULL : ent->name(); |
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
89 |
} |
41182 | 90 |
ClassFileStream* stream = new ClassFileStream(ptr, |
91 |
end_ptr - ptr, |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
92 |
pathname, |
41182 | 93 |
ClassFileStream::verify); |
94 |
ClassFileParser parser(stream, |
|
95 |
class_name, |
|
96 |
loader_data, |
|
97 |
protection_domain, |
|
98 |
NULL, |
|
99 |
NULL, |
|
100 |
ClassFileParser::BROADCAST, // publicity level |
|
101 |
CHECK_NULL); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
102 |
InstanceKlass* new_ik = parser.create_instance_klass(true /* changed_by_loadhook */, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
103 |
CHECK_NULL); |
41182 | 104 |
if (cached_class_file != NULL) { |
105 |
new_ik->set_cached_class_file(cached_class_file); |
|
106 |
} |
|
107 |
||
108 |
if (class_loader.is_null()) { |
|
109 |
ResourceMark rm; |
|
110 |
ClassLoader::add_package(class_name->as_C_string(), path_index, THREAD); |
|
111 |
} |
|
112 |
||
113 |
return new_ik; |
|
114 |
} |
|
115 |
} |
|
116 |
#endif |
|
117 |
||
118 |
return NULL; |
|
119 |
} |
|
120 |
||
121 |
||
40658
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
122 |
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
|
123 |
Symbol* name, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
124 |
ClassLoaderData* loader_data, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
125 |
Handle protection_domain, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
126 |
JvmtiCachedClassFileData** cached_class_file, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
127 |
TRAPS) { |
34666 | 128 |
|
129 |
assert(stream != NULL, "invariant"); |
|
130 |
||
131 |
if (JvmtiExport::should_post_class_file_load_hook()) { |
|
132 |
assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
|
133 |
const JavaThread* jt = (JavaThread*)THREAD; |
|
134 |
||
135 |
Handle class_loader(THREAD, loader_data->class_loader()); |
|
136 |
||
137 |
// Get the cached class file bytes (if any) from the class that |
|
138 |
// is being redefined or retransformed. We use jvmti_thread_state() |
|
139 |
// instead of JvmtiThreadState::state_for(jt) so we don't allocate |
|
140 |
// a JvmtiThreadState any earlier than necessary. This will help |
|
141 |
// avoid the bug described by 7126851. |
|
142 |
||
143 |
JvmtiThreadState* state = jt->jvmti_thread_state(); |
|
144 |
||
145 |
if (state != NULL) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
146 |
Klass* k = state->get_class_being_redefined(); |
34666 | 147 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
148 |
if (k != NULL) { |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
149 |
InstanceKlass* class_being_redefined = InstanceKlass::cast(k); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
150 |
*cached_class_file = class_being_redefined->get_cached_class_file(); |
34666 | 151 |
} |
152 |
} |
|
153 |
||
154 |
unsigned char* ptr = const_cast<unsigned char*>(stream->buffer()); |
|
155 |
unsigned char* end_ptr = ptr + stream->length(); |
|
156 |
||
157 |
JvmtiExport::post_class_file_load_hook(name, |
|
158 |
class_loader, |
|
159 |
protection_domain, |
|
160 |
&ptr, |
|
161 |
&end_ptr, |
|
162 |
cached_class_file); |
|
163 |
||
164 |
if (ptr != stream->buffer()) { |
|
165 |
// JVMTI agent has modified class file data. |
|
166 |
// Set new class file stream using JVMTI agent modified class file data. |
|
167 |
stream = new ClassFileStream(ptr, |
|
168 |
end_ptr - ptr, |
|
169 |
stream->source(), |
|
170 |
stream->need_verify()); |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
return stream; |
|
175 |
} |
|
176 |
||
177 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
178 |
InstanceKlass* KlassFactory::create_from_stream(ClassFileStream* stream, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
179 |
Symbol* name, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
180 |
ClassLoaderData* loader_data, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
181 |
Handle protection_domain, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
182 |
const InstanceKlass* host_klass, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
183 |
GrowableArray<Handle>* cp_patches, |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
184 |
TRAPS) { |
34666 | 185 |
assert(stream != NULL, "invariant"); |
186 |
assert(loader_data != NULL, "invariant"); |
|
187 |
assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
|
188 |
||
189 |
ResourceMark rm; |
|
190 |
HandleMark hm; |
|
191 |
||
192 |
JvmtiCachedClassFileData* cached_class_file = NULL; |
|
193 |
||
36508 | 194 |
ClassFileStream* old_stream = stream; |
195 |
||
40658
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
196 |
// Skip this processing for VM anonymous classes |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
197 |
if (host_klass == NULL) { |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
198 |
stream = check_class_file_load_hook(stream, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
199 |
name, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
200 |
loader_data, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
201 |
protection_domain, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
202 |
&cached_class_file, |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
203 |
CHECK_NULL); |
50dd5daad1e6
8163973: VM Anonymous classes should not call Class File Load Hooks
rprotacio
parents:
40016
diff
changeset
|
204 |
} |
34666 | 205 |
|
206 |
ClassFileParser parser(stream, |
|
207 |
name, |
|
208 |
loader_data, |
|
209 |
protection_domain, |
|
210 |
host_klass, |
|
211 |
cp_patches, |
|
212 |
ClassFileParser::BROADCAST, // publicity level |
|
213 |
CHECK_NULL); |
|
214 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
215 |
InstanceKlass* result = parser.create_instance_klass(old_stream != stream, CHECK_NULL); |
36508 | 216 |
assert(result == parser.create_instance_klass(old_stream != stream, THREAD), "invariant"); |
34666 | 217 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
42650
diff
changeset
|
218 |
if (result == NULL) { |
34666 | 219 |
return NULL; |
220 |
} |
|
221 |
||
222 |
if (cached_class_file != NULL) { |
|
223 |
// JVMTI: we have an InstanceKlass now, tell it about the cached bytes |
|
224 |
result->set_cached_class_file(cached_class_file); |
|
225 |
} |
|
226 |
||
47668 | 227 |
if (result->should_store_fingerprint()) { |
228 |
result->store_fingerprint(stream->compute_fingerprint()); |
|
42650 | 229 |
} |
230 |
||
36386
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
231 |
TRACE_KLASS_CREATION(result, parser, THREAD); |
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
232 |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
233 |
#if INCLUDE_CDS |
41182 | 234 |
if (DumpSharedSpaces) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
49480
diff
changeset
|
235 |
ClassLoader::record_result(result, stream, THREAD); |
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
236 |
#if INCLUDE_JVMTI |
41182 | 237 |
assert(cached_class_file == NULL, "Sanity"); |
238 |
// Archive the class stream data into the optional data section |
|
239 |
JvmtiCachedClassFileData *p; |
|
240 |
int len; |
|
241 |
const unsigned char *bytes; |
|
242 |
// event based tracing might set cached_class_file |
|
243 |
if ((bytes = result->get_cached_class_file_bytes()) != NULL) { |
|
244 |
len = result->get_cached_class_file_len(); |
|
245 |
} else { |
|
246 |
len = stream->length(); |
|
247 |
bytes = stream->buffer(); |
|
248 |
} |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46329
diff
changeset
|
249 |
p = (JvmtiCachedClassFileData*)os::malloc(offset_of(JvmtiCachedClassFileData, data) + len, mtInternal); |
41182 | 250 |
p->length = len; |
251 |
memcpy(p->data, bytes, len); |
|
252 |
result->set_archived_class_data(p); |
|
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
253 |
#endif // INCLUDE_JVMTI |
41182 | 254 |
} |
47103
a993ec29ec75
8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
46746
diff
changeset
|
255 |
#endif // INCLUDE_CDS |
41182 | 256 |
|
34666 | 257 |
return result; |
258 |
} |