< prev index next >

src/share/vm/classfile/javaClasses.cpp

Print this page




 756   create_mirror(k, Handle(NULL), Handle(NULL), Handle(NULL), CHECK);
 757 }
 758 
 759 void java_lang_Class::initialize_mirror_fields(KlassHandle k,
 760                                                Handle mirror,
 761                                                Handle protection_domain,
 762                                                TRAPS) {
 763   // Allocate a simple java object for a lock.
 764   // This needs to be a java object because during class initialization
 765   // it can be held across a java call.
 766   typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
 767   set_init_lock(mirror(), r);
 768 
 769   // Set protection domain also
 770   set_protection_domain(mirror(), protection_domain());
 771 
 772   // Initialize static fields
 773   InstanceKlass::cast(k())->do_local_static_fields(&initialize_static_field, mirror, CHECK);
 774 }
 775 



































 776 void java_lang_Class::create_mirror(KlassHandle k, Handle class_loader,
 777                                     Handle module, Handle protection_domain, TRAPS) {
 778   assert(k->java_mirror() == NULL, "should only assign mirror once");
 779   // Use this moment of initialization to cache modifier_flags also,
 780   // to support Class.getModifiers().  Instance classes recalculate
 781   // the cached flags after the class file is parsed, but before the
 782   // class is put into the system dictionary.
 783   int computed_modifiers = k->compute_modifier_flags(CHECK);
 784   k->set_modifier_flags(computed_modifiers);
 785   // Class_klass has to be loaded because it is used to allocate
 786   // the mirror.
 787   if (SystemDictionary::Class_klass_loaded()) {
 788     // Allocate mirror (java.lang.Class instance)
 789     Handle mirror = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 790 
 791     // Setup indirection from mirror->klass
 792     if (!k.is_null()) {
 793       java_lang_Class::set_klass(mirror(), k());
 794     }
 795 


 818       set_array_klass(comp_mirror(), k());
 819     } else {
 820       assert(k->is_instance_klass(), "Must be");
 821 
 822       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
 823       if (HAS_PENDING_EXCEPTION) {
 824         // If any of the fields throws an exception like OOM remove the klass field
 825         // from the mirror so GC doesn't follow it after the klass has been deallocated.
 826         // This mirror looks like a primitive type, which logically it is because it
 827         // it represents no class.
 828         java_lang_Class::set_klass(mirror(), NULL);
 829         return;
 830       }
 831     }
 832 
 833     // set the classLoader field in the java_lang_Class instance
 834     assert(class_loader() == k->class_loader(), "should be same");
 835     set_class_loader(mirror(), class_loader());
 836 
 837     // set the module field in the java_lang_Class instance
 838     // This may be null during bootstrap but will get fixed up later on.
 839     set_module(mirror(), module());
 840 
 841     // Setup indirection from klass->mirror last
 842     // after any exceptions can happen during allocations.
 843     if (!k.is_null()) {
 844       k->set_java_mirror(mirror());
 845     }
 846 
 847     // Keep list of classes needing java.base module fixup.
 848     if (!ModuleEntryTable::javabase_defined()) {
 849       if (fixup_module_field_list() == NULL) {
 850         GrowableArray<Klass*>* list =
 851           new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
 852         set_fixup_module_field_list(list);
 853       }
 854       k->class_loader_data()->inc_keep_alive();
 855       fixup_module_field_list()->push(k());
 856     }
 857   } else {
 858     if (fixup_mirror_list() == NULL) {
 859       GrowableArray<Klass*>* list =
 860        new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
 861       set_fixup_mirror_list(list);
 862     }
 863     fixup_mirror_list()->push(k());
 864   }
 865 }
 866 
 867 void java_lang_Class::fixup_module_field(KlassHandle k, Handle module) {
 868   assert(_module_offset != 0, "must have been computed already");
 869   java_lang_Class::set_module(k->java_mirror(), module());
 870 }
 871 
 872 int  java_lang_Class::oop_size(oop java_class) {
 873   assert(_oop_size_offset != 0, "must be set");
 874   int size = java_class->int_field(_oop_size_offset);
 875   assert(size > 0, "Oop size must be greater than zero, not %d", size);




 756   create_mirror(k, Handle(NULL), Handle(NULL), Handle(NULL), CHECK);
 757 }
 758 
 759 void java_lang_Class::initialize_mirror_fields(KlassHandle k,
 760                                                Handle mirror,
 761                                                Handle protection_domain,
 762                                                TRAPS) {
 763   // Allocate a simple java object for a lock.
 764   // This needs to be a java object because during class initialization
 765   // it can be held across a java call.
 766   typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
 767   set_init_lock(mirror(), r);
 768 
 769   // Set protection domain also
 770   set_protection_domain(mirror(), protection_domain());
 771 
 772   // Initialize static fields
 773   InstanceKlass::cast(k())->do_local_static_fields(&initialize_static_field, mirror, CHECK);
 774 }
 775 
 776 // Set the java.lang.reflect.Module module field in the java_lang_Class mirror
 777 void java_lang_Class::set_mirror_module_field(KlassHandle k, Handle mirror, Handle module, TRAPS) {
 778   if (module.is_null()) {
 779     // During startup, the module may be NULL only if java.base has not been defined yet.
 780     // Put the class on the fixup_module_list to patch later when the java.lang.reflect.Module
 781     // for java.base is known.
 782     assert(!Universe::is_module_initialized(), "Incorrect java.lang.reflect.Module pre module system initialization");
 783     MutexLocker m1(Module_lock, THREAD);
 784     // Keep list of classes needing java.base module fixup
 785     if (!ModuleEntryTable::javabase_defined()) {
 786       if (fixup_module_field_list() == NULL) {
 787         GrowableArray<Klass*>* list =
 788           new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
 789         set_fixup_module_field_list(list);
 790       }
 791       k->class_loader_data()->inc_keep_alive();
 792       fixup_module_field_list()->push(k());
 793     } else {
 794       // java.base was defined at some point between calling create_mirror()
 795       // and obtaining the Module_lock, patch this particular class with java.base.
 796       ModuleEntry *javabase_entry = ModuleEntryTable::javabase_moduleEntry();
 797       assert(javabase_entry != NULL && javabase_entry->module() != NULL,
 798              "Setting class module field, java.base should be defined");
 799       Handle javabase_handle(THREAD, JNIHandles::resolve(javabase_entry->module()));
 800       set_module(mirror(), javabase_handle());
 801     }
 802   } else {
 803     assert(Universe::is_module_initialized() ||
 804            (ModuleEntryTable::javabase_defined() &&
 805             (module() == JNIHandles::resolve(ModuleEntryTable::javabase_moduleEntry()->module()))),
 806            "Incorrect java.lang.reflect.Module specification while creating mirror");
 807     set_module(mirror(), module());
 808   }
 809 }
 810 
 811 void java_lang_Class::create_mirror(KlassHandle k, Handle class_loader,
 812                                     Handle module, Handle protection_domain, TRAPS) {
 813   assert(k->java_mirror() == NULL, "should only assign mirror once");
 814   // Use this moment of initialization to cache modifier_flags also,
 815   // to support Class.getModifiers().  Instance classes recalculate
 816   // the cached flags after the class file is parsed, but before the
 817   // class is put into the system dictionary.
 818   int computed_modifiers = k->compute_modifier_flags(CHECK);
 819   k->set_modifier_flags(computed_modifiers);
 820   // Class_klass has to be loaded because it is used to allocate
 821   // the mirror.
 822   if (SystemDictionary::Class_klass_loaded()) {
 823     // Allocate mirror (java.lang.Class instance)
 824     Handle mirror = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 825 
 826     // Setup indirection from mirror->klass
 827     if (!k.is_null()) {
 828       java_lang_Class::set_klass(mirror(), k());
 829     }
 830 


 853       set_array_klass(comp_mirror(), k());
 854     } else {
 855       assert(k->is_instance_klass(), "Must be");
 856 
 857       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
 858       if (HAS_PENDING_EXCEPTION) {
 859         // If any of the fields throws an exception like OOM remove the klass field
 860         // from the mirror so GC doesn't follow it after the klass has been deallocated.
 861         // This mirror looks like a primitive type, which logically it is because it
 862         // it represents no class.
 863         java_lang_Class::set_klass(mirror(), NULL);
 864         return;
 865       }
 866     }
 867 
 868     // set the classLoader field in the java_lang_Class instance
 869     assert(class_loader() == k->class_loader(), "should be same");
 870     set_class_loader(mirror(), class_loader());
 871 
 872     // set the module field in the java_lang_Class instance
 873     set_mirror_module_field(k, mirror, module, THREAD);

 874 
 875     // Setup indirection from klass->mirror last
 876     // after any exceptions can happen during allocations.
 877     if (!k.is_null()) {
 878       k->set_java_mirror(mirror());











 879     }
 880   } else {
 881     if (fixup_mirror_list() == NULL) {
 882       GrowableArray<Klass*>* list =
 883        new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
 884       set_fixup_mirror_list(list);
 885     }
 886     fixup_mirror_list()->push(k());
 887   }
 888 }
 889 
 890 void java_lang_Class::fixup_module_field(KlassHandle k, Handle module) {
 891   assert(_module_offset != 0, "must have been computed already");
 892   java_lang_Class::set_module(k->java_mirror(), module());
 893 }
 894 
 895 int  java_lang_Class::oop_size(oop java_class) {
 896   assert(_oop_size_offset != 0, "must be set");
 897   int size = java_class->int_field(_oop_size_offset);
 898   assert(size > 0, "Oop size must be greater than zero, not %d", size);


< prev index next >