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/altHashing.hpp"
27 #include "classfile/classLoaderData.inline.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/debugInfo.hpp"
33 #include "code/dependencyContext.hpp"
34 #include "code/pcDesc.hpp"
35 #include "interpreter/interpreter.hpp"
36 #include "interpreter/linkResolver.hpp"
37 #include "logging/log.hpp"
38 #include "logging/logStream.hpp"
39 #include "memory/oopFactory.hpp"
40 #include "memory/metaspaceShared.inline.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "memory/universe.hpp"
43 #include "oops/fieldStreams.hpp"
44 #include "oops/instanceKlass.hpp"
45 #include "oops/instanceMirrorKlass.hpp"
46 #include "oops/klass.hpp"
47 #include "oops/method.inline.hpp"
48 #include "oops/objArrayOop.inline.hpp"
49 #include "oops/oop.inline.hpp"
50 #include "oops/symbol.hpp"
51 #include "oops/typeArrayOop.inline.hpp"
52 #include "prims/resolvedMethodTable.hpp"
53 #include "runtime/fieldDescriptor.inline.hpp"
54 #include "runtime/frame.inline.hpp"
55 #include "runtime/handles.inline.hpp"
56 #include "runtime/interfaceSupport.inline.hpp"
57 #include "runtime/java.hpp"
58 #include "runtime/javaCalls.hpp"
59 #include "runtime/jniHandles.inline.hpp"
60 #include "runtime/safepoint.hpp"
733 break;
734 case T_SHORT:
735 mirror()->short_field_put(fd->offset(), fd->int_initial_value());
736 break;
737 case T_INT:
738 mirror()->int_field_put(fd->offset(), fd->int_initial_value());
739 break;
740 case T_FLOAT:
741 mirror()->float_field_put(fd->offset(), fd->float_initial_value());
742 break;
743 case T_DOUBLE:
744 mirror()->double_field_put(fd->offset(), fd->double_initial_value());
745 break;
746 case T_LONG:
747 mirror()->long_field_put(fd->offset(), fd->long_initial_value());
748 break;
749 case T_OBJECT:
750 {
751 assert(fd->signature() == vmSymbols::string_signature(),
752 "just checking");
753 if (DumpSharedSpaces && MetaspaceShared::is_archive_object(mirror())) {
754 // Archive the String field and update the pointer.
755 oop s = mirror()->obj_field(fd->offset());
756 oop archived_s = StringTable::create_archived_string(s, CHECK);
757 mirror()->obj_field_put(fd->offset(), archived_s);
758 } else {
759 oop string = fd->string_initial_value(CHECK);
760 mirror()->obj_field_put(fd->offset(), string);
761 }
762 }
763 break;
764 default:
765 THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
766 "Illegal ConstantValue attribute in class file");
767 }
768 }
769 }
770
771
772 void java_lang_Class::fixup_mirror(Klass* k, TRAPS) {
773 assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
774
775 // If the offset was read from the shared archive, it was fixed up already
776 if (!k->is_shared()) {
777 if (k->is_instance_klass()) {
778 // During bootstrap, java.lang.Class wasn't loaded so static field
779 // offsets were computed without the size added it. Go back and
780 // update all the static field offsets to included the size.
781 for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
782 if (fs.access_flags().is_static()) {
783 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
784 fs.set_offset(real_offset);
785 }
786 }
787 }
788 }
789
790 if (k->is_shared() && k->has_raw_archived_mirror()) {
791 if (MetaspaceShared::open_archive_heap_region_mapped()) {
792 bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
793 assert(present, "Missing archived mirror for %s", k->external_name());
794 return;
795 } else {
796 k->set_java_mirror_handle(NULL);
797 k->clear_has_raw_archived_mirror();
798 }
799 }
800 create_mirror(k, Handle(), Handle(), Handle(), CHECK);
801 }
802
803 void java_lang_Class::initialize_mirror_fields(Klass* k,
804 Handle mirror,
805 Handle protection_domain,
806 TRAPS) {
807 // Allocate a simple java object for a lock.
808 // This needs to be a java object because during class initialization
809 // it can be held across a java call.
810 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
811 set_init_lock(mirror(), r);
994 break;
995 case T_BOOLEAN:
996 _m()->bool_field_put(fd->offset(), false);
997 break;
998 case T_ARRAY:
999 case T_OBJECT: {
1000 // It might be useful to cache the String field, but
1001 // for now just clear out any reference field
1002 oop o = _m()->obj_field(fd->offset());
1003 _m()->obj_field_put(fd->offset(), NULL);
1004 break;
1005 }
1006 default:
1007 ShouldNotReachHere();
1008 break;
1009 }
1010 }
1011 };
1012
1013 void java_lang_Class::archive_basic_type_mirrors(TRAPS) {
1014 assert(MetaspaceShared::is_heap_object_archiving_allowed(),
1015 "MetaspaceShared::is_heap_object_archiving_allowed() must be true");
1016
1017 for (int t = 0; t <= T_VOID; t++) {
1018 oop m = Universe::_mirrors[t];
1019 if (m != NULL) {
1020 // Update the field at _array_klass_offset to point to the relocated array klass.
1021 oop archived_m = MetaspaceShared::archive_heap_object(m, THREAD);
1022 assert(archived_m != NULL, "sanity");
1023 Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset));
1024 assert(ak != NULL || t == T_VOID, "should not be NULL");
1025 if (ak != NULL) {
1026 Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak);
1027 archived_m->metadata_field_put(_array_klass_offset, reloc_ak);
1028 }
1029
1030 // Clear the fields. Just to be safe
1031 Klass *k = m->klass();
1032 Handle archived_mirror_h(THREAD, archived_m);
1033 ResetMirrorField reset(archived_mirror_h);
1034 InstanceKlass::cast(k)->do_nonstatic_fields(&reset);
1035
1036 log_trace(cds, heap, mirror)(
1037 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1038 type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m));
1039
1040 Universe::_mirrors[t] = archived_m;
1041 }
1054 Universe::set_int_mirror(Universe::_mirrors[T_INT]);
1055 Universe::set_float_mirror(Universe::_mirrors[T_FLOAT]);
1056 Universe::set_double_mirror(Universe::_mirrors[T_DOUBLE]);
1057 Universe::set_byte_mirror(Universe::_mirrors[T_BYTE]);
1058 Universe::set_bool_mirror(Universe::_mirrors[T_BOOLEAN]);
1059 Universe::set_char_mirror(Universe::_mirrors[T_CHAR]);
1060 Universe::set_long_mirror(Universe::_mirrors[T_LONG]);
1061 Universe::set_short_mirror(Universe::_mirrors[T_SHORT]);
1062 Universe::set_void_mirror(Universe::_mirrors[T_VOID]);
1063 }
1064
1065 //
1066 // After the mirror object is successfully archived, the archived
1067 // klass is set with _has_archived_raw_mirror flag.
1068 //
1069 // The _has_archived_raw_mirror flag is cleared at runtime when the
1070 // archived mirror is restored. If archived java heap data cannot
1071 // be used at runtime, new mirror object is created for the shared
1072 // class. The _has_archived_raw_mirror is cleared also during the process.
1073 oop java_lang_Class::archive_mirror(Klass* k, TRAPS) {
1074 assert(MetaspaceShared::is_heap_object_archiving_allowed(),
1075 "MetaspaceShared::is_heap_object_archiving_allowed() must be true");
1076
1077 // Mirror is already archived
1078 if (k->has_raw_archived_mirror()) {
1079 assert(k->archived_java_mirror_raw() != NULL, "no archived mirror");
1080 return k->archived_java_mirror_raw();
1081 }
1082
1083 // No mirror
1084 oop mirror = k->java_mirror();
1085 if (mirror == NULL) {
1086 return NULL;
1087 }
1088
1089 if (k->is_instance_klass()) {
1090 InstanceKlass *ik = InstanceKlass::cast(k);
1091 assert(ik->signers() == NULL && !k->has_signer_and_not_archived(),
1092 "class with signer cannot be supported");
1093
1094 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1095 ik->is_shared_app_class())) {
1096 // Archiving mirror for classes from non-builtin loaders is not
1097 // supported. Clear the _java_mirror within the archived class.
1098 k->set_java_mirror_handle(NULL);
1099 return NULL;
1100 }
1101 }
1102
1103 // Now start archiving the mirror object
1104 oop archived_mirror = MetaspaceShared::archive_heap_object(mirror, THREAD);
1105 if (archived_mirror == NULL) {
1106 return NULL;
1107 }
1108
1109 archived_mirror = process_archived_mirror(k, mirror, archived_mirror, THREAD);
1110 if (archived_mirror == NULL) {
1111 return NULL;
1112 }
1113
1114 k->set_archived_java_mirror_raw(archived_mirror);
1115
1116 k->set_has_raw_archived_mirror();
1117
1118 ResourceMark rm;
1119 log_trace(cds, heap, mirror)(
1120 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1121 k->external_name(), p2i(mirror), p2i(archived_mirror));
1122
1123 return archived_mirror;
1124 }
1125
1126 // The process is based on create_mirror().
1127 oop java_lang_Class::process_archived_mirror(Klass* k, oop mirror,
1128 oop archived_mirror,
1129 Thread *THREAD) {
1130 // Clear nonstatic fields in archived mirror. Some of the fields will be set
1131 // to archived metadata and objects below.
1132 Klass *c = archived_mirror->klass();
1133 Handle archived_mirror_h(THREAD, archived_mirror);
1134 ResetMirrorField reset(archived_mirror_h);
1135 InstanceKlass::cast(c)->do_nonstatic_fields(&reset);
1136
1137 if (k->is_array_klass()) {
1138 oop archived_comp_mirror;
1139 if (k->is_typeArray_klass()) {
1140 // The primitive type mirrors are already archived. Get the archived mirror.
1141 oop comp_mirror = java_lang_Class::component_mirror(mirror);
1142 archived_comp_mirror = MetaspaceShared::find_archived_heap_object(comp_mirror);
1143 assert(archived_comp_mirror != NULL, "Must be");
1144 } else {
1145 assert(k->is_objArray_klass(), "Must be");
1146 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1147 assert(element_klass != NULL, "Must have an element klass");
1148 archived_comp_mirror = archive_mirror(element_klass, THREAD);
1149 if (archived_comp_mirror == NULL) {
1150 return NULL;
1151 }
1152 }
1153 java_lang_Class::set_component_mirror(archived_mirror, archived_comp_mirror);
1154 } else {
1155 assert(k->is_instance_klass(), "Must be");
1156
1157 // Reset local static fields in the mirror
1158 InstanceKlass::cast(k)->do_local_static_fields(&reset);
1159
1160 java_lang_Class:set_init_lock(archived_mirror, NULL);
1161
1162 set_protection_domain(archived_mirror, NULL);
1185 p2i(arr), p2i(reloc_arr));
1186 archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr);
1187 }
1188 return archived_mirror;
1189 }
1190
1191 // Returns true if the mirror is updated, false if no archived mirror
1192 // data is present. After the archived mirror object is restored, the
1193 // shared klass' _has_raw_archived_mirror flag is cleared.
1194 bool java_lang_Class::restore_archived_mirror(Klass *k,
1195 Handle class_loader, Handle module,
1196 Handle protection_domain, TRAPS) {
1197 // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1198 // see more details in SystemDictionary::resolve_preloaded_classes().
1199 if (!SystemDictionary::Class_klass_loaded()) {
1200 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1201 fixup_mirror_list()->push(k);
1202 return true;
1203 }
1204
1205 oop m = MetaspaceShared::materialize_archived_object(k->archived_java_mirror_raw_narrow());
1206
1207 if (m == NULL) {
1208 return false;
1209 }
1210
1211 log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
1212
1213 // mirror is archived, restore
1214 assert(MetaspaceShared::is_archive_object(m), "must be archived mirror object");
1215 Handle mirror(THREAD, m);
1216
1217 if (!k->is_array_klass()) {
1218 // - local static final fields with initial values were initialized at dump time
1219
1220 // create the init_lock
1221 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1222 set_init_lock(mirror(), r);
1223
1224 if (protection_domain.not_null()) {
1225 set_protection_domain(mirror(), protection_domain());
1226 }
1227 }
1228
1229 assert(class_loader() == k->class_loader(), "should be same");
1230 if (class_loader.not_null()) {
1231 set_class_loader(mirror(), class_loader());
1232 }
1233
1234 k->set_java_mirror(mirror);
|
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/altHashing.hpp"
27 #include "classfile/classLoaderData.inline.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "classfile/moduleEntry.hpp"
30 #include "classfile/stringTable.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/debugInfo.hpp"
33 #include "code/dependencyContext.hpp"
34 #include "code/pcDesc.hpp"
35 #include "interpreter/interpreter.hpp"
36 #include "interpreter/linkResolver.hpp"
37 #include "logging/log.hpp"
38 #include "logging/logStream.hpp"
39 #include "memory/heapShared.inline.hpp"
40 #include "memory/metaspaceShared.hpp"
41 #include "memory/oopFactory.hpp"
42 #include "memory/resourceArea.hpp"
43 #include "memory/universe.hpp"
44 #include "oops/fieldStreams.hpp"
45 #include "oops/instanceKlass.hpp"
46 #include "oops/instanceMirrorKlass.hpp"
47 #include "oops/klass.hpp"
48 #include "oops/method.inline.hpp"
49 #include "oops/objArrayOop.inline.hpp"
50 #include "oops/oop.inline.hpp"
51 #include "oops/symbol.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "prims/resolvedMethodTable.hpp"
54 #include "runtime/fieldDescriptor.inline.hpp"
55 #include "runtime/frame.inline.hpp"
56 #include "runtime/handles.inline.hpp"
57 #include "runtime/interfaceSupport.inline.hpp"
58 #include "runtime/java.hpp"
59 #include "runtime/javaCalls.hpp"
60 #include "runtime/jniHandles.inline.hpp"
61 #include "runtime/safepoint.hpp"
734 break;
735 case T_SHORT:
736 mirror()->short_field_put(fd->offset(), fd->int_initial_value());
737 break;
738 case T_INT:
739 mirror()->int_field_put(fd->offset(), fd->int_initial_value());
740 break;
741 case T_FLOAT:
742 mirror()->float_field_put(fd->offset(), fd->float_initial_value());
743 break;
744 case T_DOUBLE:
745 mirror()->double_field_put(fd->offset(), fd->double_initial_value());
746 break;
747 case T_LONG:
748 mirror()->long_field_put(fd->offset(), fd->long_initial_value());
749 break;
750 case T_OBJECT:
751 {
752 assert(fd->signature() == vmSymbols::string_signature(),
753 "just checking");
754 if (DumpSharedSpaces && HeapShared::is_archived_object(mirror())) {
755 // Archive the String field and update the pointer.
756 oop s = mirror()->obj_field(fd->offset());
757 oop archived_s = StringTable::create_archived_string(s, CHECK);
758 mirror()->obj_field_put(fd->offset(), archived_s);
759 } else {
760 oop string = fd->string_initial_value(CHECK);
761 mirror()->obj_field_put(fd->offset(), string);
762 }
763 }
764 break;
765 default:
766 THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
767 "Illegal ConstantValue attribute in class file");
768 }
769 }
770 }
771
772
773 void java_lang_Class::fixup_mirror(Klass* k, TRAPS) {
774 assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
775
776 // If the offset was read from the shared archive, it was fixed up already
777 if (!k->is_shared()) {
778 if (k->is_instance_klass()) {
779 // During bootstrap, java.lang.Class wasn't loaded so static field
780 // offsets were computed without the size added it. Go back and
781 // update all the static field offsets to included the size.
782 for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
783 if (fs.access_flags().is_static()) {
784 int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
785 fs.set_offset(real_offset);
786 }
787 }
788 }
789 }
790
791 if (k->is_shared() && k->has_raw_archived_mirror()) {
792 if (HeapShared::open_archive_heap_region_mapped()) {
793 bool present = restore_archived_mirror(k, Handle(), Handle(), Handle(), CHECK);
794 assert(present, "Missing archived mirror for %s", k->external_name());
795 return;
796 } else {
797 k->set_java_mirror_handle(NULL);
798 k->clear_has_raw_archived_mirror();
799 }
800 }
801 create_mirror(k, Handle(), Handle(), Handle(), CHECK);
802 }
803
804 void java_lang_Class::initialize_mirror_fields(Klass* k,
805 Handle mirror,
806 Handle protection_domain,
807 TRAPS) {
808 // Allocate a simple java object for a lock.
809 // This needs to be a java object because during class initialization
810 // it can be held across a java call.
811 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
812 set_init_lock(mirror(), r);
995 break;
996 case T_BOOLEAN:
997 _m()->bool_field_put(fd->offset(), false);
998 break;
999 case T_ARRAY:
1000 case T_OBJECT: {
1001 // It might be useful to cache the String field, but
1002 // for now just clear out any reference field
1003 oop o = _m()->obj_field(fd->offset());
1004 _m()->obj_field_put(fd->offset(), NULL);
1005 break;
1006 }
1007 default:
1008 ShouldNotReachHere();
1009 break;
1010 }
1011 }
1012 };
1013
1014 void java_lang_Class::archive_basic_type_mirrors(TRAPS) {
1015 assert(HeapShared::is_heap_object_archiving_allowed(),
1016 "HeapShared::is_heap_object_archiving_allowed() must be true");
1017
1018 for (int t = 0; t <= T_VOID; t++) {
1019 oop m = Universe::_mirrors[t];
1020 if (m != NULL) {
1021 // Update the field at _array_klass_offset to point to the relocated array klass.
1022 oop archived_m = HeapShared::archive_heap_object(m, THREAD);
1023 assert(archived_m != NULL, "sanity");
1024 Klass *ak = (Klass*)(archived_m->metadata_field(_array_klass_offset));
1025 assert(ak != NULL || t == T_VOID, "should not be NULL");
1026 if (ak != NULL) {
1027 Klass *reloc_ak = MetaspaceShared::get_relocated_klass(ak);
1028 archived_m->metadata_field_put(_array_klass_offset, reloc_ak);
1029 }
1030
1031 // Clear the fields. Just to be safe
1032 Klass *k = m->klass();
1033 Handle archived_mirror_h(THREAD, archived_m);
1034 ResetMirrorField reset(archived_mirror_h);
1035 InstanceKlass::cast(k)->do_nonstatic_fields(&reset);
1036
1037 log_trace(cds, heap, mirror)(
1038 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1039 type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m));
1040
1041 Universe::_mirrors[t] = archived_m;
1042 }
1055 Universe::set_int_mirror(Universe::_mirrors[T_INT]);
1056 Universe::set_float_mirror(Universe::_mirrors[T_FLOAT]);
1057 Universe::set_double_mirror(Universe::_mirrors[T_DOUBLE]);
1058 Universe::set_byte_mirror(Universe::_mirrors[T_BYTE]);
1059 Universe::set_bool_mirror(Universe::_mirrors[T_BOOLEAN]);
1060 Universe::set_char_mirror(Universe::_mirrors[T_CHAR]);
1061 Universe::set_long_mirror(Universe::_mirrors[T_LONG]);
1062 Universe::set_short_mirror(Universe::_mirrors[T_SHORT]);
1063 Universe::set_void_mirror(Universe::_mirrors[T_VOID]);
1064 }
1065
1066 //
1067 // After the mirror object is successfully archived, the archived
1068 // klass is set with _has_archived_raw_mirror flag.
1069 //
1070 // The _has_archived_raw_mirror flag is cleared at runtime when the
1071 // archived mirror is restored. If archived java heap data cannot
1072 // be used at runtime, new mirror object is created for the shared
1073 // class. The _has_archived_raw_mirror is cleared also during the process.
1074 oop java_lang_Class::archive_mirror(Klass* k, TRAPS) {
1075 assert(HeapShared::is_heap_object_archiving_allowed(),
1076 "HeapShared::is_heap_object_archiving_allowed() must be true");
1077
1078 // Mirror is already archived
1079 if (k->has_raw_archived_mirror()) {
1080 assert(k->archived_java_mirror_raw() != NULL, "no archived mirror");
1081 return k->archived_java_mirror_raw();
1082 }
1083
1084 // No mirror
1085 oop mirror = k->java_mirror();
1086 if (mirror == NULL) {
1087 return NULL;
1088 }
1089
1090 if (k->is_instance_klass()) {
1091 InstanceKlass *ik = InstanceKlass::cast(k);
1092 assert(ik->signers() == NULL && !k->has_signer_and_not_archived(),
1093 "class with signer cannot be supported");
1094
1095 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
1096 ik->is_shared_app_class())) {
1097 // Archiving mirror for classes from non-builtin loaders is not
1098 // supported. Clear the _java_mirror within the archived class.
1099 k->set_java_mirror_handle(NULL);
1100 return NULL;
1101 }
1102 }
1103
1104 // Now start archiving the mirror object
1105 oop archived_mirror = HeapShared::archive_heap_object(mirror, THREAD);
1106 if (archived_mirror == NULL) {
1107 return NULL;
1108 }
1109
1110 archived_mirror = process_archived_mirror(k, mirror, archived_mirror, THREAD);
1111 if (archived_mirror == NULL) {
1112 return NULL;
1113 }
1114
1115 k->set_archived_java_mirror_raw(archived_mirror);
1116
1117 k->set_has_raw_archived_mirror();
1118
1119 ResourceMark rm;
1120 log_trace(cds, heap, mirror)(
1121 "Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1122 k->external_name(), p2i(mirror), p2i(archived_mirror));
1123
1124 return archived_mirror;
1125 }
1126
1127 // The process is based on create_mirror().
1128 oop java_lang_Class::process_archived_mirror(Klass* k, oop mirror,
1129 oop archived_mirror,
1130 Thread *THREAD) {
1131 // Clear nonstatic fields in archived mirror. Some of the fields will be set
1132 // to archived metadata and objects below.
1133 Klass *c = archived_mirror->klass();
1134 Handle archived_mirror_h(THREAD, archived_mirror);
1135 ResetMirrorField reset(archived_mirror_h);
1136 InstanceKlass::cast(c)->do_nonstatic_fields(&reset);
1137
1138 if (k->is_array_klass()) {
1139 oop archived_comp_mirror;
1140 if (k->is_typeArray_klass()) {
1141 // The primitive type mirrors are already archived. Get the archived mirror.
1142 oop comp_mirror = java_lang_Class::component_mirror(mirror);
1143 archived_comp_mirror = HeapShared::find_archived_heap_object(comp_mirror);
1144 assert(archived_comp_mirror != NULL, "Must be");
1145 } else {
1146 assert(k->is_objArray_klass(), "Must be");
1147 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1148 assert(element_klass != NULL, "Must have an element klass");
1149 archived_comp_mirror = archive_mirror(element_klass, THREAD);
1150 if (archived_comp_mirror == NULL) {
1151 return NULL;
1152 }
1153 }
1154 java_lang_Class::set_component_mirror(archived_mirror, archived_comp_mirror);
1155 } else {
1156 assert(k->is_instance_klass(), "Must be");
1157
1158 // Reset local static fields in the mirror
1159 InstanceKlass::cast(k)->do_local_static_fields(&reset);
1160
1161 java_lang_Class:set_init_lock(archived_mirror, NULL);
1162
1163 set_protection_domain(archived_mirror, NULL);
1186 p2i(arr), p2i(reloc_arr));
1187 archived_mirror->metadata_field_put(_array_klass_offset, reloc_arr);
1188 }
1189 return archived_mirror;
1190 }
1191
1192 // Returns true if the mirror is updated, false if no archived mirror
1193 // data is present. After the archived mirror object is restored, the
1194 // shared klass' _has_raw_archived_mirror flag is cleared.
1195 bool java_lang_Class::restore_archived_mirror(Klass *k,
1196 Handle class_loader, Handle module,
1197 Handle protection_domain, TRAPS) {
1198 // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1199 // see more details in SystemDictionary::resolve_preloaded_classes().
1200 if (!SystemDictionary::Class_klass_loaded()) {
1201 assert(fixup_mirror_list() != NULL, "fixup_mirror_list not initialized");
1202 fixup_mirror_list()->push(k);
1203 return true;
1204 }
1205
1206 oop m = HeapShared::materialize_archived_object(k->archived_java_mirror_raw_narrow());
1207
1208 if (m == NULL) {
1209 return false;
1210 }
1211
1212 log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
1213
1214 // mirror is archived, restore
1215 assert(HeapShared::is_archived_object(m), "must be archived mirror object");
1216 Handle mirror(THREAD, m);
1217
1218 if (!k->is_array_klass()) {
1219 // - local static final fields with initial values were initialized at dump time
1220
1221 // create the init_lock
1222 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1223 set_init_lock(mirror(), r);
1224
1225 if (protection_domain.not_null()) {
1226 set_protection_domain(mirror(), protection_domain());
1227 }
1228 }
1229
1230 assert(class_loader() == k->class_loader(), "should be same");
1231 if (class_loader.not_null()) {
1232 set_class_loader(mirror(), class_loader());
1233 }
1234
1235 k->set_java_mirror(mirror);
|