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/constantPool.hpp"
42 #include "oops/instanceKlass.hpp"
43 #include "oops/objArrayKlass.hpp"
44 #include "oops/objArrayOop.inline.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "runtime/fieldType.hpp"
47 #include "runtime/init.hpp"
48 #include "runtime/javaCalls.hpp"
49 #include "runtime/signature.hpp"
50 #include "runtime/vframe.hpp"
51 #include "utilities/copy.hpp"
52 #if INCLUDE_ALL_GCS
53 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
54 #endif // INCLUDE_ALL_GCS
55
56 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
57 Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);
58 int size = ConstantPool::size(length);
59 return new (loader_data, size, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
60 }
61
62 #ifdef ASSERT
63
64 // MetaspaceObj allocation invariant is calloc equivalent memory
65 // simple verification of this here (JVM_CONSTANT_Invalid == 0 )
66 static bool tag_array_is_zero_initialized(Array<u1>* tags) {
67 assert(tags != NULL, "invariant");
68 const int length = tags->length();
69 for (int index = 0; index < length; ++index) {
70 if (JVM_CONSTANT_Invalid != tags->at(index)) {
71 return false;
72 }
73 }
74 return true;
313 }
314 }
315 #endif
316
317 // CDS support. Create a new resolved_references array.
318 void ConstantPool::restore_unshareable_info(TRAPS) {
319 assert(is_constantPool(), "ensure C++ vtable is restored");
320 assert(on_stack(), "should always be set for shared constant pools");
321 assert(is_shared(), "should always be set for shared constant pools");
322 assert(_cache != NULL, "constant pool _cache should not be NULL");
323
324 // Only create the new resolved references array if it hasn't been attempted before
325 if (resolved_references() != NULL) return;
326
327 // restore the C++ vtable from the shared archive
328 restore_vtable();
329
330 if (SystemDictionary::Object_klass_loaded()) {
331 ClassLoaderData* loader_data = pool_holder()->class_loader_data();
332 #if INCLUDE_CDS_JAVA_HEAP
333 if (MetaspaceShared::open_archive_heap_region_mapped() &&
334 _cache->archived_references() != NULL) {
335 oop archived = _cache->archived_references();
336 // Make sure GC knows the cached object is now live. This is necessary after
337 // initial GC marking and during concurrent marking as strong roots are only
338 // scanned during initial marking (at the start of the GC marking).
339 assert(UseG1GC, "Requires G1 GC");
340 G1SATBCardTableModRefBS::enqueue(archived);
341 // Create handle for the archived resolved reference array object
342 Handle refs_handle(THREAD, (oop)archived);
343 set_resolved_references(loader_data->add_handle(refs_handle));
344 } else
345 #endif
346 {
347 // No mapped archived resolved reference array
348 // Recreate the object array and add to ClassLoaderData.
349 int map_length = resolved_reference_length();
350 if (map_length > 0) {
351 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
352 Handle refs_handle(THREAD, (oop)stom); // must handleize.
353 set_resolved_references(loader_data->add_handle(refs_handle));
354 }
355 }
356 }
357 }
358
359 void ConstantPool::remove_unshareable_info() {
360 // Resolved references are not in the shared archive.
361 // Save the length for restoration. It is not necessarily the same length
362 // as reference_map.length() if invokedynamic is saved. It is needed when
363 // re-creating the resolved reference array if archived heap data cannot be map
|
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/constantPool.hpp"
42 #include "oops/instanceKlass.hpp"
43 #include "oops/objArrayKlass.hpp"
44 #include "oops/objArrayOop.inline.hpp"
45 #include "oops/oop.inline.hpp"
46 #include "runtime/fieldType.hpp"
47 #include "runtime/init.hpp"
48 #include "runtime/javaCalls.hpp"
49 #include "runtime/signature.hpp"
50 #include "runtime/vframe.hpp"
51 #include "utilities/copy.hpp"
52
53 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
54 Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);
55 int size = ConstantPool::size(length);
56 return new (loader_data, size, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
57 }
58
59 #ifdef ASSERT
60
61 // MetaspaceObj allocation invariant is calloc equivalent memory
62 // simple verification of this here (JVM_CONSTANT_Invalid == 0 )
63 static bool tag_array_is_zero_initialized(Array<u1>* tags) {
64 assert(tags != NULL, "invariant");
65 const int length = tags->length();
66 for (int index = 0; index < length; ++index) {
67 if (JVM_CONSTANT_Invalid != tags->at(index)) {
68 return false;
69 }
70 }
71 return true;
310 }
311 }
312 #endif
313
314 // CDS support. Create a new resolved_references array.
315 void ConstantPool::restore_unshareable_info(TRAPS) {
316 assert(is_constantPool(), "ensure C++ vtable is restored");
317 assert(on_stack(), "should always be set for shared constant pools");
318 assert(is_shared(), "should always be set for shared constant pools");
319 assert(_cache != NULL, "constant pool _cache should not be NULL");
320
321 // Only create the new resolved references array if it hasn't been attempted before
322 if (resolved_references() != NULL) return;
323
324 // restore the C++ vtable from the shared archive
325 restore_vtable();
326
327 if (SystemDictionary::Object_klass_loaded()) {
328 ClassLoaderData* loader_data = pool_holder()->class_loader_data();
329 #if INCLUDE_CDS_JAVA_HEAP
330 if (MetaspaceShared::open_archive_heap_region_mapped()) {
331 oop archived = _cache->archived_references();
332 if (archived != NULL) {
333 // Create handle for the archived resolved reference array object
334 Handle refs_handle(THREAD, archived);
335 set_resolved_references(loader_data->add_handle(refs_handle));
336 }
337 } else
338 #endif
339 {
340 // No mapped archived resolved reference array
341 // Recreate the object array and add to ClassLoaderData.
342 int map_length = resolved_reference_length();
343 if (map_length > 0) {
344 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
345 Handle refs_handle(THREAD, (oop)stom); // must handleize.
346 set_resolved_references(loader_data->add_handle(refs_handle));
347 }
348 }
349 }
350 }
351
352 void ConstantPool::remove_unshareable_info() {
353 // Resolved references are not in the shared archive.
354 // Save the length for restoration. It is not necessarily the same length
355 // as reference_map.length() if invokedynamic is saved. It is needed when
356 // re-creating the resolved reference array if archived heap data cannot be map
|