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 "jvm.h"
27 #include "classfile/classLoaderData.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "classfile/metadataOnStackMark.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "classfile/systemDictionary.hpp"
32 #include "classfile/vmSymbols.hpp"
33 #include "interpreter/linkResolver.hpp"
34 #include "memory/allocation.inline.hpp"
35 #include "memory/heapInspection.hpp"
36 #include "memory/metadataFactory.hpp"
37 #include "memory/metaspaceClosure.hpp"
38 #include "memory/metaspaceShared.hpp"
39 #include "memory/oopFactory.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "oops/array.inline.hpp"
42 #include "oops/constantPool.inline.hpp"
43 #include "oops/cpCache.inline.hpp"
44 #include "oops/instanceKlass.hpp"
45 #include "oops/objArrayKlass.hpp"
46 #include "oops/objArrayOop.inline.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "oops/typeArrayOop.inline.hpp"
49 #include "runtime/fieldType.hpp"
50 #include "runtime/handles.inline.hpp"
51 #include "runtime/init.hpp"
52 #include "runtime/javaCalls.hpp"
53 #include "runtime/signature.hpp"
54 #include "runtime/vframe.inline.hpp"
55 #include "utilities/copy.hpp"
278 int ref_map_len = ref_map == NULL ? 0 : ref_map->length();
279 int rr_len = rr->length();
280 for (int i = 0; i < rr_len; i++) {
281 oop p = rr->obj_at(i);
282 rr->obj_at_put(i, NULL);
283 if (p != NULL && i < ref_map_len) {
284 int index = object_to_cp_index(i);
285 // Skip the entry if the string hash code is 0 since the string
286 // is not included in the shared string_table, see StringTable::copy_shared_string.
287 if (tag_at(index).is_string() && java_lang_String::hash_code(p) != 0) {
288 oop op = StringTable::create_archived_string(p, THREAD);
289 // If the String object is not archived (possibly too large),
290 // NULL is returned. Also set it in the array, so we won't
291 // have a 'bad' reference in the archived resolved_reference
292 // array.
293 rr->obj_at_put(i, op);
294 }
295 }
296 }
297
298 oop archived = MetaspaceShared::archive_heap_object(rr, THREAD);
299 // If the resolved references array is not archived (too large),
300 // the 'archived' object is NULL. No need to explicitly check
301 // the return value of archive_heap_object here. At runtime, the
302 // resolved references will be created using the normal process
303 // when there is no archived value.
304 _cache->set_archived_references(archived);
305 set_resolved_references(NULL);
306 }
307 }
308
309 void ConstantPool::resolve_class_constants(TRAPS) {
310 assert(DumpSharedSpaces, "used during dump time only");
311 // The _cache may be NULL if the _pool_holder klass fails verification
312 // at dump time due to missing dependencies.
313 if (cache() == NULL || reference_map() == NULL) {
314 return; // nothing to do
315 }
316
317 constantPoolHandle cp(THREAD, this);
318 for (int index = 1; index < length(); index++) { // Index 0 is unused
323 }
324 }
325 #endif
326
327 // CDS support. Create a new resolved_references array.
328 void ConstantPool::restore_unshareable_info(TRAPS) {
329 assert(is_constantPool(), "ensure C++ vtable is restored");
330 assert(on_stack(), "should always be set for shared constant pools");
331 assert(is_shared(), "should always be set for shared constant pools");
332 assert(_cache != NULL, "constant pool _cache should not be NULL");
333
334 // Only create the new resolved references array if it hasn't been attempted before
335 if (resolved_references() != NULL) return;
336
337 // restore the C++ vtable from the shared archive
338 restore_vtable();
339
340 if (SystemDictionary::Object_klass_loaded()) {
341 ClassLoaderData* loader_data = pool_holder()->class_loader_data();
342 #if INCLUDE_CDS_JAVA_HEAP
343 if (MetaspaceShared::open_archive_heap_region_mapped() &&
344 _cache->archived_references() != NULL) {
345 oop archived = _cache->archived_references();
346 // Create handle for the archived resolved reference array object
347 Handle refs_handle(THREAD, archived);
348 set_resolved_references(loader_data->add_handle(refs_handle));
349 } else
350 #endif
351 {
352 // No mapped archived resolved reference array
353 // Recreate the object array and add to ClassLoaderData.
354 int map_length = resolved_reference_length();
355 if (map_length > 0) {
356 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
357 Handle refs_handle(THREAD, (oop)stom); // must handleize.
358 set_resolved_references(loader_data->add_handle(refs_handle));
359 }
360 }
361 }
362 }
363
364 void ConstantPool::remove_unshareable_info() {
365 // Resolved references are not in the shared archive.
366 // Save the length for restoration. It is not necessarily the same length
367 // as reference_map.length() if invokedynamic is saved. It is needed when
368 // re-creating the resolved reference array if archived heap data cannot be map
369 // at runtime.
370 set_resolved_reference_length(
371 resolved_references() != NULL ? resolved_references()->length() : 0);
372
373 // If archiving heap objects is not allowed, clear the resolved references.
374 // Otherwise, it is cleared after the resolved references array is cached
375 // (see archive_resolved_references()).
376 if (!MetaspaceShared::is_heap_object_archiving_allowed()) {
377 set_resolved_references(NULL);
378 }
379
380 // Shared ConstantPools are in the RO region, so the _flags cannot be modified.
381 // The _on_stack flag is used to prevent ConstantPools from deallocation during
382 // class redefinition. Since shared ConstantPools cannot be deallocated anyway,
383 // we always set _on_stack to true to avoid having to change _flags during runtime.
384 _flags |= (_on_stack | _is_shared);
385 int num_klasses = 0;
386 for (int index = 1; index < length(); index++) { // Index 0 is unused
387 assert(!tag_at(index).is_unresolved_klass_in_error(), "This must not happen during dump time");
388 if (tag_at(index).is_klass()) {
389 // This class was resolved as a side effect of executing Java code
390 // during dump time. We need to restore it back to an UnresolvedClass,
391 // so that the proper class loading and initialization can happen
392 // at runtime.
393 CPKlassSlot kslot = klass_slot_at(index);
394 int resolved_klass_index = kslot.resolved_klass_index();
395 int name_index = kslot.name_index();
396 assert(tag_at(name_index).is_symbol(), "sanity");
|
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 "jvm.h"
27 #include "classfile/classLoaderData.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "classfile/metadataOnStackMark.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "classfile/systemDictionary.hpp"
32 #include "classfile/vmSymbols.hpp"
33 #include "interpreter/linkResolver.hpp"
34 #include "memory/allocation.inline.hpp"
35 #include "memory/heapInspection.hpp"
36 #include "memory/heapShared.hpp"
37 #include "memory/metadataFactory.hpp"
38 #include "memory/metaspaceClosure.hpp"
39 #include "memory/metaspaceShared.hpp"
40 #include "memory/oopFactory.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "oops/array.inline.hpp"
43 #include "oops/constantPool.inline.hpp"
44 #include "oops/cpCache.inline.hpp"
45 #include "oops/instanceKlass.hpp"
46 #include "oops/objArrayKlass.hpp"
47 #include "oops/objArrayOop.inline.hpp"
48 #include "oops/oop.inline.hpp"
49 #include "oops/typeArrayOop.inline.hpp"
50 #include "runtime/fieldType.hpp"
51 #include "runtime/handles.inline.hpp"
52 #include "runtime/init.hpp"
53 #include "runtime/javaCalls.hpp"
54 #include "runtime/signature.hpp"
55 #include "runtime/vframe.inline.hpp"
56 #include "utilities/copy.hpp"
279 int ref_map_len = ref_map == NULL ? 0 : ref_map->length();
280 int rr_len = rr->length();
281 for (int i = 0; i < rr_len; i++) {
282 oop p = rr->obj_at(i);
283 rr->obj_at_put(i, NULL);
284 if (p != NULL && i < ref_map_len) {
285 int index = object_to_cp_index(i);
286 // Skip the entry if the string hash code is 0 since the string
287 // is not included in the shared string_table, see StringTable::copy_shared_string.
288 if (tag_at(index).is_string() && java_lang_String::hash_code(p) != 0) {
289 oop op = StringTable::create_archived_string(p, THREAD);
290 // If the String object is not archived (possibly too large),
291 // NULL is returned. Also set it in the array, so we won't
292 // have a 'bad' reference in the archived resolved_reference
293 // array.
294 rr->obj_at_put(i, op);
295 }
296 }
297 }
298
299 oop archived = HeapShared::archive_heap_object(rr, THREAD);
300 // If the resolved references array is not archived (too large),
301 // the 'archived' object is NULL. No need to explicitly check
302 // the return value of archive_heap_object here. At runtime, the
303 // resolved references will be created using the normal process
304 // when there is no archived value.
305 _cache->set_archived_references(archived);
306 set_resolved_references(NULL);
307 }
308 }
309
310 void ConstantPool::resolve_class_constants(TRAPS) {
311 assert(DumpSharedSpaces, "used during dump time only");
312 // The _cache may be NULL if the _pool_holder klass fails verification
313 // at dump time due to missing dependencies.
314 if (cache() == NULL || reference_map() == NULL) {
315 return; // nothing to do
316 }
317
318 constantPoolHandle cp(THREAD, this);
319 for (int index = 1; index < length(); index++) { // Index 0 is unused
324 }
325 }
326 #endif
327
328 // CDS support. Create a new resolved_references array.
329 void ConstantPool::restore_unshareable_info(TRAPS) {
330 assert(is_constantPool(), "ensure C++ vtable is restored");
331 assert(on_stack(), "should always be set for shared constant pools");
332 assert(is_shared(), "should always be set for shared constant pools");
333 assert(_cache != NULL, "constant pool _cache should not be NULL");
334
335 // Only create the new resolved references array if it hasn't been attempted before
336 if (resolved_references() != NULL) return;
337
338 // restore the C++ vtable from the shared archive
339 restore_vtable();
340
341 if (SystemDictionary::Object_klass_loaded()) {
342 ClassLoaderData* loader_data = pool_holder()->class_loader_data();
343 #if INCLUDE_CDS_JAVA_HEAP
344 if (HeapShared::open_archive_heap_region_mapped() &&
345 _cache->archived_references() != NULL) {
346 oop archived = _cache->archived_references();
347 // Create handle for the archived resolved reference array object
348 Handle refs_handle(THREAD, archived);
349 set_resolved_references(loader_data->add_handle(refs_handle));
350 } else
351 #endif
352 {
353 // No mapped archived resolved reference array
354 // Recreate the object array and add to ClassLoaderData.
355 int map_length = resolved_reference_length();
356 if (map_length > 0) {
357 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
358 Handle refs_handle(THREAD, (oop)stom); // must handleize.
359 set_resolved_references(loader_data->add_handle(refs_handle));
360 }
361 }
362 }
363 }
364
365 void ConstantPool::remove_unshareable_info() {
366 // Resolved references are not in the shared archive.
367 // Save the length for restoration. It is not necessarily the same length
368 // as reference_map.length() if invokedynamic is saved. It is needed when
369 // re-creating the resolved reference array if archived heap data cannot be map
370 // at runtime.
371 set_resolved_reference_length(
372 resolved_references() != NULL ? resolved_references()->length() : 0);
373
374 // If archiving heap objects is not allowed, clear the resolved references.
375 // Otherwise, it is cleared after the resolved references array is cached
376 // (see archive_resolved_references()).
377 if (!HeapShared::is_heap_object_archiving_allowed()) {
378 set_resolved_references(NULL);
379 }
380
381 // Shared ConstantPools are in the RO region, so the _flags cannot be modified.
382 // The _on_stack flag is used to prevent ConstantPools from deallocation during
383 // class redefinition. Since shared ConstantPools cannot be deallocated anyway,
384 // we always set _on_stack to true to avoid having to change _flags during runtime.
385 _flags |= (_on_stack | _is_shared);
386 int num_klasses = 0;
387 for (int index = 1; index < length(); index++) { // Index 0 is unused
388 assert(!tag_at(index).is_unresolved_klass_in_error(), "This must not happen during dump time");
389 if (tag_at(index).is_klass()) {
390 // This class was resolved as a side effect of executing Java code
391 // during dump time. We need to restore it back to an UnresolvedClass,
392 // so that the proper class loading and initialization can happen
393 // at runtime.
394 CPKlassSlot kslot = klass_slot_at(index);
395 int resolved_klass_index = kslot.resolved_klass_index();
396 int name_index = kslot.name_index();
397 assert(tag_at(name_index).is_symbol(), "sanity");
|