< prev index next >

src/share/vm/classfile/javaClasses.cpp

Print this page




 718         mirror()->long_field_put(fd->offset(), fd->long_initial_value());
 719         break;
 720       case T_OBJECT:
 721         {
 722           #ifdef ASSERT
 723           TempNewSymbol sym = SymbolTable::new_symbol("Ljava/lang/String;", CHECK);
 724           assert(fd->signature() == sym, "just checking");
 725           #endif
 726           oop string = fd->string_initial_value(CHECK);
 727           mirror()->obj_field_put(fd->offset(), string);
 728         }
 729         break;
 730       default:
 731         THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
 732                   "Illegal ConstantValue attribute in class file");
 733     }
 734   }
 735 }
 736 
 737 
 738 void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) {
 739   assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
 740 
 741   // If the offset was read from the shared archive, it was fixed up already
 742   if (!k->is_shared()) {
 743     if (k->is_instance_klass()) {
 744       // During bootstrap, java.lang.Class wasn't loaded so static field
 745       // offsets were computed without the size added it.  Go back and
 746       // update all the static field offsets to included the size.
 747         for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) {
 748         if (fs.access_flags().is_static()) {
 749           int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
 750           fs.set_offset(real_offset);
 751         }
 752       }
 753     }
 754   }
 755   create_mirror(k, Handle(), Handle(), Handle(), CHECK);
 756 }
 757 
 758 void java_lang_Class::initialize_mirror_fields(KlassHandle k,
 759                                                Handle mirror,
 760                                                Handle protection_domain,
 761                                                TRAPS) {
 762   // Allocate a simple java object for a lock.
 763   // This needs to be a java object because during class initialization
 764   // it can be held across a java call.
 765   typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
 766   set_init_lock(mirror(), r);
 767 
 768   // Set protection domain also
 769   set_protection_domain(mirror(), protection_domain());
 770 
 771   // Initialize static fields
 772   InstanceKlass::cast(k())->do_local_static_fields(&initialize_static_field, mirror, CHECK);
 773 }
 774 
 775 // Set the java.lang.reflect.Module module field in the java_lang_Class mirror
 776 void java_lang_Class::set_mirror_module_field(KlassHandle k, Handle mirror, Handle module, TRAPS) {
 777   if (module.is_null()) {
 778     // During startup, the module may be NULL only if java.base has not been defined yet.
 779     // Put the class on the fixup_module_list to patch later when the java.lang.reflect.Module
 780     // for java.base is known.
 781     assert(!Universe::is_module_initialized(), "Incorrect java.lang.reflect.Module pre module system initialization");
 782 
 783     bool javabase_was_defined = false;
 784     {
 785       MutexLocker m1(Module_lock, THREAD);
 786       // Keep list of classes needing java.base module fixup
 787       if (!ModuleEntryTable::javabase_defined()) {
 788         if (fixup_module_field_list() == NULL) {
 789           GrowableArray<Klass*>* list =
 790             new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
 791           set_fixup_module_field_list(list);
 792         }
 793         k->class_loader_data()->inc_keep_alive();
 794         fixup_module_field_list()->push(k());
 795       } else {
 796         javabase_was_defined = true;
 797       }
 798     }
 799 
 800     // If java.base was already defined then patch this particular class with java.base.
 801     if (javabase_was_defined) {
 802       ModuleEntry *javabase_entry = ModuleEntryTable::javabase_moduleEntry();
 803       assert(javabase_entry != NULL && javabase_entry->module() != NULL,
 804              "Setting class module field, " JAVA_BASE_NAME " should be defined");
 805       Handle javabase_handle(THREAD, JNIHandles::resolve(javabase_entry->module()));
 806       set_module(mirror(), javabase_handle());
 807     }
 808   } else {
 809     assert(Universe::is_module_initialized() ||
 810            (ModuleEntryTable::javabase_defined() &&
 811             (module() == JNIHandles::resolve(ModuleEntryTable::javabase_moduleEntry()->module()))),
 812            "Incorrect java.lang.reflect.Module specification while creating mirror");
 813     set_module(mirror(), module());
 814   }
 815 }
 816 
 817 void java_lang_Class::create_mirror(KlassHandle k, Handle class_loader,
 818                                     Handle module, Handle protection_domain, TRAPS) {
 819   assert(k->java_mirror() == NULL, "should only assign mirror once");
 820   // Use this moment of initialization to cache modifier_flags also,
 821   // to support Class.getModifiers().  Instance classes recalculate
 822   // the cached flags after the class file is parsed, but before the
 823   // class is put into the system dictionary.
 824   int computed_modifiers = k->compute_modifier_flags(CHECK);
 825   k->set_modifier_flags(computed_modifiers);
 826   // Class_klass has to be loaded because it is used to allocate
 827   // the mirror.
 828   if (SystemDictionary::Class_klass_loaded()) {
 829     // Allocate mirror (java.lang.Class instance)
 830     oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 831     Handle mirror(THREAD, mirror_oop);
 832 
 833     // Setup indirection from mirror->klass
 834     if (!k.is_null()) {
 835       java_lang_Class::set_klass(mirror(), k());
 836     }
 837 
 838     InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
 839     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
 840 
 841     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 842 
 843     // It might also have a component mirror.  This mirror must already exist.
 844     if (k->is_array_klass()) {
 845       oop comp_mirror;
 846       if (k->is_typeArray_klass()) {
 847         BasicType type = TypeArrayKlass::cast(k())->element_type();
 848         comp_mirror = Universe::java_mirror(type);
 849       } else {
 850         assert(k->is_objArray_klass(), "Must be");
 851         Klass* element_klass = ObjArrayKlass::cast(k())->element_klass();
 852         assert(element_klass != NULL, "Must have an element klass");
 853         comp_mirror = element_klass->java_mirror();
 854       }
 855       assert(comp_mirror != NULL, "must have a mirror");
 856 
 857       // Two-way link between the array klass and its component mirror:
 858       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
 859       set_component_mirror(mirror(), comp_mirror);
 860       set_array_klass(comp_mirror, k());
 861     } else {
 862       assert(k->is_instance_klass(), "Must be");
 863 
 864       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
 865       if (HAS_PENDING_EXCEPTION) {
 866         // If any of the fields throws an exception like OOM remove the klass field
 867         // from the mirror so GC doesn't follow it after the klass has been deallocated.
 868         // This mirror looks like a primitive type, which logically it is because it
 869         // it represents no class.
 870         java_lang_Class::set_klass(mirror(), NULL);
 871         return;
 872       }
 873     }
 874 
 875     // set the classLoader field in the java_lang_Class instance
 876     assert(class_loader() == k->class_loader(), "should be same");
 877     set_class_loader(mirror(), class_loader());
 878 
 879     // set the module field in the java_lang_Class instance
 880     set_mirror_module_field(k, mirror, module, THREAD);
 881 
 882     // Setup indirection from klass->mirror last
 883     // after any exceptions can happen during allocations.
 884     if (!k.is_null()) {
 885       k->set_java_mirror(mirror());
 886     }
 887   } else {
 888     if (fixup_mirror_list() == NULL) {
 889       GrowableArray<Klass*>* list =
 890        new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
 891       set_fixup_mirror_list(list);
 892     }
 893     fixup_mirror_list()->push(k());
 894   }
 895 }
 896 
 897 void java_lang_Class::fixup_module_field(KlassHandle k, Handle module) {
 898   assert(_module_offset != 0, "must have been computed already");
 899   java_lang_Class::set_module(k->java_mirror(), module());
 900 }
 901 
 902 int  java_lang_Class::oop_size(oop java_class) {
 903   assert(_oop_size_offset != 0, "must be set");
 904   int size = java_class->int_field(_oop_size_offset);
 905   assert(size > 0, "Oop size must be greater than zero, not %d", size);
 906   return size;
 907 }
 908 
 909 void java_lang_Class::set_oop_size(oop java_class, int size) {
 910   assert(_oop_size_offset != 0, "must be set");
 911   assert(size > 0, "Oop size must be greater than zero, not %d", size);
 912   java_class->int_field_put(_oop_size_offset, size);
 913 }
 914 
 915 int  java_lang_Class::static_oop_field_count(oop java_class) {
 916   assert(_static_oop_field_count_offset != 0, "must be set");
 917   return java_class->int_field(_static_oop_field_count_offset);


1859   // Now print the stack trace.
1860   Thread* THREAD = Thread::current();
1861   while (throwable.not_null()) {
1862     objArrayHandle result (THREAD, objArrayOop(backtrace(throwable())));
1863     if (result.is_null()) {
1864       st->print_raw_cr("\t<<no stack trace available>>");
1865       return;
1866     }
1867     BacktraceIterator iter(result, THREAD);
1868 
1869     while (iter.repeat()) {
1870       BacktraceElement bte = iter.next(THREAD);
1871       print_stack_element_to_stream(st, bte._mirror, bte._method_id, bte._version, bte._bci, bte._name);
1872     }
1873     {
1874       // Call getCause() which doesn't necessarily return the _cause field.
1875       EXCEPTION_MARK;
1876       JavaValue cause(T_OBJECT);
1877       JavaCalls::call_virtual(&cause,
1878                               throwable,
1879                               KlassHandle(THREAD, throwable->klass()),
1880                               vmSymbols::getCause_name(),
1881                               vmSymbols::void_throwable_signature(),
1882                               THREAD);
1883       // Ignore any exceptions. we are in the middle of exception handling. Same as classic VM.
1884       if (HAS_PENDING_EXCEPTION) {
1885         CLEAR_PENDING_EXCEPTION;
1886         throwable = Handle();
1887       } else {
1888         throwable = Handle(THREAD, (oop) cause.get_jobject());
1889         if (throwable.not_null()) {
1890           st->print("Caused by: ");
1891           print(throwable(), st);
1892           st->cr();
1893         }
1894       }
1895     }
1896   }
1897 }
1898 
1899 /**
1900  * Print the throwable stack trace by calling the Java method java.lang.Throwable.printStackTrace().
1901  */
1902 void java_lang_Throwable::java_printStackTrace(Handle throwable, TRAPS) {
1903   assert(throwable->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected");
1904   JavaValue result(T_VOID);
1905   JavaCalls::call_virtual(&result,
1906                           throwable,
1907                           KlassHandle(THREAD, SystemDictionary::Throwable_klass()),
1908                           vmSymbols::printStackTrace_name(),
1909                           vmSymbols::void_method_signature(),
1910                           THREAD);
1911 }
1912 
1913 void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS) {
1914   if (!StackTraceInThrowable) return;
1915   ResourceMark rm(THREAD);
1916 
1917   // Start out by clearing the backtrace for this object, in case the VM
1918   // runs out of memory while allocating the stack trace
1919   set_backtrace(throwable(), NULL);
1920   // Clear lazily constructed Java level stacktrace if refilling occurs
1921   // This is unnecessary in 1.7+ but harmless
1922   clear_stacktrace(throwable());
1923 
1924   int max_depth = MaxJavaStackTraceDepth;
1925   JavaThread* thread = (JavaThread*)THREAD;
1926 
1927   BacktraceBuilder bt(CHECK);


2136 
2137     Handle stack_trace_element(THREAD, stack_trace_array_h->obj_at(index++));
2138 
2139     if (stack_trace_element.is_null()) {
2140       THROW(vmSymbols::java_lang_NullPointerException());
2141     }
2142 
2143     InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror()));
2144     methodHandle method (THREAD, holder->method_with_orig_idnum(bte._method_id, bte._version));
2145 
2146     java_lang_StackTraceElement::fill_in(stack_trace_element, holder,
2147                                          method,
2148                                          bte._version,
2149                                          bte._bci,
2150                                          bte._name, CHECK);
2151   }
2152 }
2153 
2154 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
2155   // Allocate java.lang.StackTraceElement instance
2156   Klass* k = SystemDictionary::StackTraceElement_klass();
2157   assert(k != NULL, "must be loaded in 1.4+");
2158   instanceKlassHandle ik (THREAD, k);
2159   if (ik->should_be_initialized()) {
2160     ik->initialize(CHECK_0);
2161   }
2162 
2163   Handle element = ik->allocate_instance_handle(CHECK_0);
2164 
2165   int version = method->constants()->version();
2166   fill_in(element, method->method_holder(), method, version, bci, method->name(), CHECK_0);
2167   return element();
2168 }
2169 
2170 void java_lang_StackTraceElement::fill_in(Handle element,
2171                                           InstanceKlass* holder, const methodHandle& method,
2172                                           int version, int bci, Symbol* name, TRAPS) {
2173   assert(element->is_a(SystemDictionary::StackTraceElement_klass()), "sanity check");
2174 
2175   // Fill in class name
2176   ResourceMark rm(THREAD);
2177   const char* str = holder->external_name();
2178   oop classname = StringTable::intern((char*) str, CHECK);
2179   java_lang_StackTraceElement::set_declaringClass(element(), classname);
2180   java_lang_StackTraceElement::set_declaringClassObject(element(), holder->java_mirror());
2181 
2182   oop loader = holder->class_loader();
2183   if (loader != NULL) {


2472   compute_offset(clazz_offset,          k, vmSymbols::clazz_name(),          vmSymbols::class_signature());
2473   compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature());
2474   compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature());
2475   compute_offset(slot_offset,           k, vmSymbols::slot_name(),           vmSymbols::int_signature());
2476   compute_offset(modifiers_offset,      k, vmSymbols::modifiers_name(),      vmSymbols::int_signature());
2477   // The generic signature and annotations fields are only present in 1.5
2478   signature_offset = -1;
2479   annotations_offset = -1;
2480   parameter_annotations_offset = -1;
2481   type_annotations_offset = -1;
2482   compute_optional_offset(signature_offset,             k, vmSymbols::signature_name(),             vmSymbols::string_signature());
2483   compute_optional_offset(annotations_offset,           k, vmSymbols::annotations_name(),           vmSymbols::byte_array_signature());
2484   compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature());
2485   compute_optional_offset(type_annotations_offset,      k, vmSymbols::type_annotations_name(),      vmSymbols::byte_array_signature());
2486 }
2487 
2488 Handle java_lang_reflect_Constructor::create(TRAPS) {
2489   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2490   Symbol* name = vmSymbols::java_lang_reflect_Constructor();
2491   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2492   instanceKlassHandle klass (THREAD, k);
2493   // Ensure it is initialized
2494   klass->initialize(CHECK_NH);
2495   return klass->allocate_instance_handle(THREAD);
2496 }
2497 
2498 oop java_lang_reflect_Constructor::clazz(oop reflect) {
2499   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2500   return reflect->obj_field(clazz_offset);
2501 }
2502 
2503 void java_lang_reflect_Constructor::set_clazz(oop reflect, oop value) {
2504   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2505    reflect->obj_field_put(clazz_offset, value);
2506 }
2507 
2508 oop java_lang_reflect_Constructor::parameter_types(oop constructor) {
2509   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2510   return constructor->obj_field(parameterTypes_offset);
2511 }
2512 
2513 void java_lang_reflect_Constructor::set_parameter_types(oop constructor, oop value) {
2514   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2515   constructor->obj_field_put(parameterTypes_offset, value);


2612 void java_lang_reflect_Field::compute_offsets() {
2613   Klass* k = SystemDictionary::reflect_Field_klass();
2614   compute_offset(clazz_offset,     k, vmSymbols::clazz_name(),     vmSymbols::class_signature());
2615   compute_offset(name_offset,      k, vmSymbols::name_name(),      vmSymbols::string_signature());
2616   compute_offset(type_offset,      k, vmSymbols::type_name(),      vmSymbols::class_signature());
2617   compute_offset(slot_offset,      k, vmSymbols::slot_name(),      vmSymbols::int_signature());
2618   compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature());
2619   // The generic signature and annotations fields are only present in 1.5
2620   signature_offset = -1;
2621   annotations_offset = -1;
2622   type_annotations_offset = -1;
2623   compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature());
2624   compute_optional_offset(annotations_offset,  k, vmSymbols::annotations_name(),  vmSymbols::byte_array_signature());
2625   compute_optional_offset(type_annotations_offset,  k, vmSymbols::type_annotations_name(),  vmSymbols::byte_array_signature());
2626 }
2627 
2628 Handle java_lang_reflect_Field::create(TRAPS) {
2629   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2630   Symbol* name = vmSymbols::java_lang_reflect_Field();
2631   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2632   instanceKlassHandle klass (THREAD, k);
2633   // Ensure it is initialized
2634   klass->initialize(CHECK_NH);
2635   return klass->allocate_instance_handle(THREAD);
2636 }
2637 
2638 oop java_lang_reflect_Field::clazz(oop reflect) {
2639   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2640   return reflect->obj_field(clazz_offset);
2641 }
2642 
2643 void java_lang_reflect_Field::set_clazz(oop reflect, oop value) {
2644   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2645    reflect->obj_field_put(clazz_offset, value);
2646 }
2647 
2648 oop java_lang_reflect_Field::name(oop field) {
2649   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2650   return field->obj_field(name_offset);
2651 }
2652 
2653 void java_lang_reflect_Field::set_name(oop field, oop value) {
2654   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2655   field->obj_field_put(name_offset, value);


2739   if (k != NULL) {
2740     // The field is called ConstantPool* in the sun.reflect.ConstantPool class.
2741     compute_offset(_oop_offset, k, vmSymbols::ConstantPool_name(), vmSymbols::object_signature());
2742   }
2743 }
2744 
2745 void java_lang_reflect_Parameter::compute_offsets() {
2746   Klass* k = SystemDictionary::reflect_Parameter_klass();
2747   if(NULL != k) {
2748     compute_offset(name_offset,        k, vmSymbols::name_name(),        vmSymbols::string_signature());
2749     compute_offset(modifiers_offset,   k, vmSymbols::modifiers_name(),   vmSymbols::int_signature());
2750     compute_offset(index_offset,       k, vmSymbols::index_name(),       vmSymbols::int_signature());
2751     compute_offset(executable_offset,  k, vmSymbols::executable_name(),  vmSymbols::executable_signature());
2752   }
2753 }
2754 
2755 Handle java_lang_reflect_Parameter::create(TRAPS) {
2756   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2757   Symbol* name = vmSymbols::java_lang_reflect_Parameter();
2758   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2759   instanceKlassHandle klass (THREAD, k);
2760   // Ensure it is initialized
2761   klass->initialize(CHECK_NH);
2762   return klass->allocate_instance_handle(THREAD);
2763 }
2764 
2765 oop java_lang_reflect_Parameter::name(oop param) {
2766   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2767   return param->obj_field(name_offset);
2768 }
2769 
2770 void java_lang_reflect_Parameter::set_name(oop param, oop value) {
2771   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2772   param->obj_field_put(name_offset, value);
2773 }
2774 
2775 int java_lang_reflect_Parameter::modifiers(oop param) {
2776   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2777   return param->int_field(modifiers_offset);
2778 }
2779 
2780 void java_lang_reflect_Parameter::set_modifiers(oop param, int value) {
2781   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2782   param->int_field_put(modifiers_offset, value);


2795 oop java_lang_reflect_Parameter::executable(oop param) {
2796   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2797   return param->obj_field(executable_offset);
2798 }
2799 
2800 void java_lang_reflect_Parameter::set_executable(oop param, oop value) {
2801   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2802   param->obj_field_put(executable_offset, value);
2803 }
2804 
2805 
2806 int java_lang_reflect_Module::loader_offset;
2807 int java_lang_reflect_Module::name_offset;
2808 int java_lang_reflect_Module::_module_entry_offset = -1;
2809 
2810 Handle java_lang_reflect_Module::create(Handle loader, Handle module_name, TRAPS) {
2811   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2812 
2813   Symbol* name = vmSymbols::java_lang_reflect_Module();
2814   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2815   instanceKlassHandle klass (THREAD, k);
2816 
2817   Handle jlrmh = klass->allocate_instance_handle(CHECK_NH);
2818   JavaValue result(T_VOID);
2819   JavaCalls::call_special(&result, jlrmh, KlassHandle(THREAD, klass()),
2820                           vmSymbols::object_initializer_name(),
2821                           vmSymbols::java_lang_reflect_module_init_signature(),
2822                           loader, module_name, CHECK_NH);
2823   return jlrmh;
2824 }
2825 
2826 void java_lang_reflect_Module::compute_offsets() {
2827   Klass* k = SystemDictionary::reflect_Module_klass();
2828   if(NULL != k) {
2829     compute_offset(loader_offset,  k, vmSymbols::loader_name(),  vmSymbols::classloader_signature());
2830     compute_offset(name_offset,    k, vmSymbols::name_name(),    vmSymbols::string_signature());
2831     MODULE_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
2832   }
2833 }
2834 
2835 
2836 oop java_lang_reflect_Module::loader(oop module) {
2837   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2838   return module->obj_field(loader_offset);
2839 }


2862   if (module_entry == NULL) {
2863     // If the inject field containing the ModuleEntry* is null then return the
2864     // class loader's unnamed module.
2865     oop loader = java_lang_reflect_Module::loader(module);
2866     Handle h_loader = Handle(THREAD, loader);
2867     ClassLoaderData* loader_cld = SystemDictionary::register_loader(h_loader, CHECK_NULL);
2868     return loader_cld->modules()->unnamed_module();
2869   }
2870   return module_entry;
2871 }
2872 
2873 void java_lang_reflect_Module::set_module_entry(oop module, ModuleEntry* module_entry) {
2874   assert(_module_entry_offset != -1, "Uninitialized module_entry_offset");
2875   assert(module != NULL, "module can't be null");
2876   assert(module->is_oop(), "module must be oop");
2877   module->address_field_put(_module_entry_offset, (address)module_entry);
2878 }
2879 
2880 Handle reflect_ConstantPool::create(TRAPS) {
2881   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2882   Klass* k = SystemDictionary::reflect_ConstantPool_klass();
2883   instanceKlassHandle klass (THREAD, k);
2884   // Ensure it is initialized
2885   klass->initialize(CHECK_NH);
2886   return klass->allocate_instance_handle(THREAD);
2887 }
2888 
2889 
2890 void reflect_ConstantPool::set_cp(oop reflect, ConstantPool* value) {
2891   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2892   oop mirror = value->pool_holder()->java_mirror();
2893   // Save the mirror to get back the constant pool.
2894   reflect->obj_field_put(_oop_offset, mirror);
2895 }
2896 
2897 ConstantPool* reflect_ConstantPool::get_cp(oop reflect) {
2898   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2899 
2900   oop mirror = reflect->obj_field(_oop_offset);
2901   Klass* k = java_lang_Class::as_Klass(mirror);
2902   assert(k->is_instance_klass(), "Must be");
2903 
2904   // Get the constant pool back from the klass.  Since class redefinition
2905   // merges the new constant pool into the old, this is essentially the
2906   // same constant pool as the original.  If constant pool merging is
2907   // no longer done in the future, this will have to change to save
2908   // the original.
2909   return InstanceKlass::cast(k)->constants();
2910 }
2911 
2912 void reflect_UnsafeStaticFieldAccessorImpl::compute_offsets() {
2913   Klass* k = SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass();
2914   // This null test can be removed post beta
2915   if (k != NULL) {
2916     compute_offset(_base_offset, k,
2917                    vmSymbols::base_name(), vmSymbols::object_signature());
2918   }
2919 }
2920 
2921 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
2922   Klass* k = SystemDictionary::box_klass(type);
2923   if (k == NULL)  return NULL;
2924   instanceKlassHandle h (THREAD, k);
2925   if (!h->is_initialized())  h->initialize(CHECK_0);
2926   return h->allocate_instance(THREAD);
2927 }
2928 
2929 
2930 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) {
2931   oop box = initialize_and_allocate(type, CHECK_0);
2932   if (box == NULL)  return NULL;
2933   switch (type) {
2934     case T_BOOLEAN:
2935       box->bool_field_put(value_offset, value->z);
2936       break;
2937     case T_CHAR:
2938       box->char_field_put(value_offset, value->c);
2939       break;
2940     case T_FLOAT:
2941       box->float_field_put(value_offset, value->f);
2942       break;
2943     case T_DOUBLE:
2944       box->double_field_put(long_value_offset, value->d);
2945       break;
2946     case T_BYTE:


3868   reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
3869   java_lang_reflect_Parameter::compute_offsets();
3870   java_lang_reflect_Module::compute_offsets();
3871   java_lang_StackFrameInfo::compute_offsets();
3872   java_lang_LiveStackFrameInfo::compute_offsets();
3873 
3874   // generated interpreter code wants to know about the offsets we just computed:
3875   AbstractAssembler::update_delayed_values();
3876 }
3877 
3878 #ifndef PRODUCT
3879 
3880 // These functions exist to assert the validity of hard-coded field offsets to guard
3881 // against changes in the class files
3882 
3883 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
3884   EXCEPTION_MARK;
3885   fieldDescriptor fd;
3886   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
3887   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
3888   instanceKlassHandle h_klass (THREAD, k);
3889   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
3890   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
3891   if (!h_klass->find_local_field(f_name, f_sig, &fd)) {
3892     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
3893     return false;
3894   }
3895   if (fd.is_static()) {
3896     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
3897     return false;
3898   }
3899   if (fd.offset() == hardcoded_offset ) {
3900     return true;
3901   } else {
3902     tty->print_cr("Offset of nonstatic field %s.%s is hardcoded as %d but should really be %d.",
3903                   klass_name, field_name, hardcoded_offset, fd.offset());
3904     return false;
3905   }
3906 }
3907 
3908 
3909 bool JavaClasses::check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
3910   EXCEPTION_MARK;
3911   fieldDescriptor fd;
3912   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
3913   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
3914   instanceKlassHandle h_klass (THREAD, k);
3915   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
3916   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
3917   if (!h_klass->find_local_field(f_name, f_sig, &fd)) {
3918     tty->print_cr("Static field %s.%s not found", klass_name, field_name);
3919     return false;
3920   }
3921   if (!fd.is_static()) {
3922     tty->print_cr("Static field %s.%s appears to be nonstatic", klass_name, field_name);
3923     return false;
3924   }
3925   if (fd.offset() == hardcoded_offset + InstanceMirrorKlass::offset_of_static_fields()) {
3926     return true;
3927   } else {
3928     tty->print_cr("Offset of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_offset, fd.offset() - InstanceMirrorKlass::offset_of_static_fields());
3929     return false;
3930   }
3931 }
3932 
3933 
3934 bool JavaClasses::check_constant(const char *klass_name, int hardcoded_constant, const char *field_name, const char* field_sig) {
3935   EXCEPTION_MARK;
3936   fieldDescriptor fd;
3937   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
3938   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
3939   instanceKlassHandle h_klass (THREAD, k);
3940   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
3941   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
3942   if (!h_klass->find_local_field(f_name, f_sig, &fd)) {
3943     tty->print_cr("Static field %s.%s not found", klass_name, field_name);
3944     return false;
3945   }
3946   if (!fd.is_static() || !fd.has_initial_value()) {
3947     tty->print_cr("Static field %s.%s appears to be non-constant", klass_name, field_name);
3948     return false;
3949   }
3950   if (!fd.initial_value_tag().is_int()) {
3951     tty->print_cr("Static field %s.%s is not an int", klass_name, field_name);
3952     return false;
3953   }
3954   jint field_value = fd.int_initial_value();
3955   if (field_value == hardcoded_constant) {
3956     return true;
3957   } else {
3958     tty->print_cr("Constant value of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_constant, field_value);
3959     return false;
3960   }
3961 }
3962 




 718         mirror()->long_field_put(fd->offset(), fd->long_initial_value());
 719         break;
 720       case T_OBJECT:
 721         {
 722           #ifdef ASSERT
 723           TempNewSymbol sym = SymbolTable::new_symbol("Ljava/lang/String;", CHECK);
 724           assert(fd->signature() == sym, "just checking");
 725           #endif
 726           oop string = fd->string_initial_value(CHECK);
 727           mirror()->obj_field_put(fd->offset(), string);
 728         }
 729         break;
 730       default:
 731         THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
 732                   "Illegal ConstantValue attribute in class file");
 733     }
 734   }
 735 }
 736 
 737 
 738 void java_lang_Class::fixup_mirror(Klass* k, TRAPS) {
 739   assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already");
 740 
 741   // If the offset was read from the shared archive, it was fixed up already
 742   if (!k->is_shared()) {
 743     if (k->is_instance_klass()) {
 744       // During bootstrap, java.lang.Class wasn't loaded so static field
 745       // offsets were computed without the size added it.  Go back and
 746       // update all the static field offsets to included the size.
 747         for (JavaFieldStream fs(InstanceKlass::cast(k)); !fs.done(); fs.next()) {
 748         if (fs.access_flags().is_static()) {
 749           int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields();
 750           fs.set_offset(real_offset);
 751         }
 752       }
 753     }
 754   }
 755   create_mirror(k, Handle(), Handle(), Handle(), CHECK);
 756 }
 757 
 758 void java_lang_Class::initialize_mirror_fields(Klass* k,
 759                                                Handle mirror,
 760                                                Handle protection_domain,
 761                                                TRAPS) {
 762   // Allocate a simple java object for a lock.
 763   // This needs to be a java object because during class initialization
 764   // it can be held across a java call.
 765   typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK);
 766   set_init_lock(mirror(), r);
 767 
 768   // Set protection domain also
 769   set_protection_domain(mirror(), protection_domain());
 770 
 771   // Initialize static fields
 772   InstanceKlass::cast(k)->do_local_static_fields(&initialize_static_field, mirror, CHECK);
 773 }
 774 
 775 // Set the java.lang.reflect.Module module field in the java_lang_Class mirror
 776 void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle module, TRAPS) {
 777   if (module.is_null()) {
 778     // During startup, the module may be NULL only if java.base has not been defined yet.
 779     // Put the class on the fixup_module_list to patch later when the java.lang.reflect.Module
 780     // for java.base is known.
 781     assert(!Universe::is_module_initialized(), "Incorrect java.lang.reflect.Module pre module system initialization");
 782 
 783     bool javabase_was_defined = false;
 784     {
 785       MutexLocker m1(Module_lock, THREAD);
 786       // Keep list of classes needing java.base module fixup
 787       if (!ModuleEntryTable::javabase_defined()) {
 788         if (fixup_module_field_list() == NULL) {
 789           GrowableArray<Klass*>* list =
 790             new (ResourceObj::C_HEAP, mtModule) GrowableArray<Klass*>(500, true);
 791           set_fixup_module_field_list(list);
 792         }
 793         k->class_loader_data()->inc_keep_alive();
 794         fixup_module_field_list()->push(k);
 795       } else {
 796         javabase_was_defined = true;
 797       }
 798     }
 799 
 800     // If java.base was already defined then patch this particular class with java.base.
 801     if (javabase_was_defined) {
 802       ModuleEntry *javabase_entry = ModuleEntryTable::javabase_moduleEntry();
 803       assert(javabase_entry != NULL && javabase_entry->module() != NULL,
 804              "Setting class module field, " JAVA_BASE_NAME " should be defined");
 805       Handle javabase_handle(THREAD, JNIHandles::resolve(javabase_entry->module()));
 806       set_module(mirror(), javabase_handle());
 807     }
 808   } else {
 809     assert(Universe::is_module_initialized() ||
 810            (ModuleEntryTable::javabase_defined() &&
 811             (module() == JNIHandles::resolve(ModuleEntryTable::javabase_moduleEntry()->module()))),
 812            "Incorrect java.lang.reflect.Module specification while creating mirror");
 813     set_module(mirror(), module());
 814   }
 815 }
 816 
 817 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
 818                                     Handle module, Handle protection_domain, TRAPS) {
 819   assert(k->java_mirror() == NULL, "should only assign mirror once");
 820   // Use this moment of initialization to cache modifier_flags also,
 821   // to support Class.getModifiers().  Instance classes recalculate
 822   // the cached flags after the class file is parsed, but before the
 823   // class is put into the system dictionary.
 824   int computed_modifiers = k->compute_modifier_flags(CHECK);
 825   k->set_modifier_flags(computed_modifiers);
 826   // Class_klass has to be loaded because it is used to allocate
 827   // the mirror.
 828   if (SystemDictionary::Class_klass_loaded()) {
 829     // Allocate mirror (java.lang.Class instance)
 830     oop mirror_oop = InstanceMirrorKlass::cast(SystemDictionary::Class_klass())->allocate_instance(k, CHECK);
 831     Handle mirror(THREAD, mirror_oop);
 832 
 833     // Setup indirection from mirror->klass
 834     if (k != NULL) {
 835       java_lang_Class::set_klass(mirror(), k);
 836     }
 837 
 838     InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
 839     assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
 840 
 841     java_lang_Class::set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
 842 
 843     // It might also have a component mirror.  This mirror must already exist.
 844     if (k->is_array_klass()) {
 845       oop comp_mirror;
 846       if (k->is_typeArray_klass()) {
 847         BasicType type = TypeArrayKlass::cast(k)->element_type();
 848         comp_mirror = Universe::java_mirror(type);
 849       } else {
 850         assert(k->is_objArray_klass(), "Must be");
 851         Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
 852         assert(element_klass != NULL, "Must have an element klass");
 853         comp_mirror = element_klass->java_mirror();
 854       }
 855       assert(comp_mirror != NULL, "must have a mirror");
 856 
 857       // Two-way link between the array klass and its component mirror:
 858       // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
 859       set_component_mirror(mirror(), comp_mirror);
 860       set_array_klass(comp_mirror, k);
 861     } else {
 862       assert(k->is_instance_klass(), "Must be");
 863 
 864       initialize_mirror_fields(k, mirror, protection_domain, THREAD);
 865       if (HAS_PENDING_EXCEPTION) {
 866         // If any of the fields throws an exception like OOM remove the klass field
 867         // from the mirror so GC doesn't follow it after the klass has been deallocated.
 868         // This mirror looks like a primitive type, which logically it is because it
 869         // it represents no class.
 870         java_lang_Class::set_klass(mirror(), NULL);
 871         return;
 872       }
 873     }
 874 
 875     // set the classLoader field in the java_lang_Class instance
 876     assert(class_loader() == k->class_loader(), "should be same");
 877     set_class_loader(mirror(), class_loader());
 878 
 879     // set the module field in the java_lang_Class instance
 880     set_mirror_module_field(k, mirror, module, THREAD);
 881 
 882     // Setup indirection from klass->mirror last
 883     // after any exceptions can happen during allocations.
 884     if (k != NULL) {
 885       k->set_java_mirror(mirror());
 886     }
 887   } else {
 888     if (fixup_mirror_list() == NULL) {
 889       GrowableArray<Klass*>* list =
 890        new (ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(40, true);
 891       set_fixup_mirror_list(list);
 892     }
 893     fixup_mirror_list()->push(k);
 894   }
 895 }
 896 
 897 void java_lang_Class::fixup_module_field(Klass* k, Handle module) {
 898   assert(_module_offset != 0, "must have been computed already");
 899   java_lang_Class::set_module(k->java_mirror(), module());
 900 }
 901 
 902 int  java_lang_Class::oop_size(oop java_class) {
 903   assert(_oop_size_offset != 0, "must be set");
 904   int size = java_class->int_field(_oop_size_offset);
 905   assert(size > 0, "Oop size must be greater than zero, not %d", size);
 906   return size;
 907 }
 908 
 909 void java_lang_Class::set_oop_size(oop java_class, int size) {
 910   assert(_oop_size_offset != 0, "must be set");
 911   assert(size > 0, "Oop size must be greater than zero, not %d", size);
 912   java_class->int_field_put(_oop_size_offset, size);
 913 }
 914 
 915 int  java_lang_Class::static_oop_field_count(oop java_class) {
 916   assert(_static_oop_field_count_offset != 0, "must be set");
 917   return java_class->int_field(_static_oop_field_count_offset);


1859   // Now print the stack trace.
1860   Thread* THREAD = Thread::current();
1861   while (throwable.not_null()) {
1862     objArrayHandle result (THREAD, objArrayOop(backtrace(throwable())));
1863     if (result.is_null()) {
1864       st->print_raw_cr("\t<<no stack trace available>>");
1865       return;
1866     }
1867     BacktraceIterator iter(result, THREAD);
1868 
1869     while (iter.repeat()) {
1870       BacktraceElement bte = iter.next(THREAD);
1871       print_stack_element_to_stream(st, bte._mirror, bte._method_id, bte._version, bte._bci, bte._name);
1872     }
1873     {
1874       // Call getCause() which doesn't necessarily return the _cause field.
1875       EXCEPTION_MARK;
1876       JavaValue cause(T_OBJECT);
1877       JavaCalls::call_virtual(&cause,
1878                               throwable,
1879                               throwable->klass(),
1880                               vmSymbols::getCause_name(),
1881                               vmSymbols::void_throwable_signature(),
1882                               THREAD);
1883       // Ignore any exceptions. we are in the middle of exception handling. Same as classic VM.
1884       if (HAS_PENDING_EXCEPTION) {
1885         CLEAR_PENDING_EXCEPTION;
1886         throwable = Handle();
1887       } else {
1888         throwable = Handle(THREAD, (oop) cause.get_jobject());
1889         if (throwable.not_null()) {
1890           st->print("Caused by: ");
1891           print(throwable(), st);
1892           st->cr();
1893         }
1894       }
1895     }
1896   }
1897 }
1898 
1899 /**
1900  * Print the throwable stack trace by calling the Java method java.lang.Throwable.printStackTrace().
1901  */
1902 void java_lang_Throwable::java_printStackTrace(Handle throwable, TRAPS) {
1903   assert(throwable->is_a(SystemDictionary::Throwable_klass()), "Throwable instance expected");
1904   JavaValue result(T_VOID);
1905   JavaCalls::call_virtual(&result,
1906                           throwable,
1907                           SystemDictionary::Throwable_klass(),
1908                           vmSymbols::printStackTrace_name(),
1909                           vmSymbols::void_method_signature(),
1910                           THREAD);
1911 }
1912 
1913 void java_lang_Throwable::fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS) {
1914   if (!StackTraceInThrowable) return;
1915   ResourceMark rm(THREAD);
1916 
1917   // Start out by clearing the backtrace for this object, in case the VM
1918   // runs out of memory while allocating the stack trace
1919   set_backtrace(throwable(), NULL);
1920   // Clear lazily constructed Java level stacktrace if refilling occurs
1921   // This is unnecessary in 1.7+ but harmless
1922   clear_stacktrace(throwable());
1923 
1924   int max_depth = MaxJavaStackTraceDepth;
1925   JavaThread* thread = (JavaThread*)THREAD;
1926 
1927   BacktraceBuilder bt(CHECK);


2136 
2137     Handle stack_trace_element(THREAD, stack_trace_array_h->obj_at(index++));
2138 
2139     if (stack_trace_element.is_null()) {
2140       THROW(vmSymbols::java_lang_NullPointerException());
2141     }
2142 
2143     InstanceKlass* holder = InstanceKlass::cast(java_lang_Class::as_Klass(bte._mirror()));
2144     methodHandle method (THREAD, holder->method_with_orig_idnum(bte._method_id, bte._version));
2145 
2146     java_lang_StackTraceElement::fill_in(stack_trace_element, holder,
2147                                          method,
2148                                          bte._version,
2149                                          bte._bci,
2150                                          bte._name, CHECK);
2151   }
2152 }
2153 
2154 oop java_lang_StackTraceElement::create(const methodHandle& method, int bci, TRAPS) {
2155   // Allocate java.lang.StackTraceElement instance
2156   InstanceKlass* k = SystemDictionary::StackTraceElement_klass();
2157   assert(k != NULL, "must be loaded in 1.4+");
2158   if (k->should_be_initialized()) {
2159     k->initialize(CHECK_0);

2160   }
2161 
2162   Handle element = k->allocate_instance_handle(CHECK_0);
2163 
2164   int version = method->constants()->version();
2165   fill_in(element, method->method_holder(), method, version, bci, method->name(), CHECK_0);
2166   return element();
2167 }
2168 
2169 void java_lang_StackTraceElement::fill_in(Handle element,
2170                                           InstanceKlass* holder, const methodHandle& method,
2171                                           int version, int bci, Symbol* name, TRAPS) {
2172   assert(element->is_a(SystemDictionary::StackTraceElement_klass()), "sanity check");
2173 
2174   // Fill in class name
2175   ResourceMark rm(THREAD);
2176   const char* str = holder->external_name();
2177   oop classname = StringTable::intern((char*) str, CHECK);
2178   java_lang_StackTraceElement::set_declaringClass(element(), classname);
2179   java_lang_StackTraceElement::set_declaringClassObject(element(), holder->java_mirror());
2180 
2181   oop loader = holder->class_loader();
2182   if (loader != NULL) {


2471   compute_offset(clazz_offset,          k, vmSymbols::clazz_name(),          vmSymbols::class_signature());
2472   compute_offset(parameterTypes_offset, k, vmSymbols::parameterTypes_name(), vmSymbols::class_array_signature());
2473   compute_offset(exceptionTypes_offset, k, vmSymbols::exceptionTypes_name(), vmSymbols::class_array_signature());
2474   compute_offset(slot_offset,           k, vmSymbols::slot_name(),           vmSymbols::int_signature());
2475   compute_offset(modifiers_offset,      k, vmSymbols::modifiers_name(),      vmSymbols::int_signature());
2476   // The generic signature and annotations fields are only present in 1.5
2477   signature_offset = -1;
2478   annotations_offset = -1;
2479   parameter_annotations_offset = -1;
2480   type_annotations_offset = -1;
2481   compute_optional_offset(signature_offset,             k, vmSymbols::signature_name(),             vmSymbols::string_signature());
2482   compute_optional_offset(annotations_offset,           k, vmSymbols::annotations_name(),           vmSymbols::byte_array_signature());
2483   compute_optional_offset(parameter_annotations_offset, k, vmSymbols::parameter_annotations_name(), vmSymbols::byte_array_signature());
2484   compute_optional_offset(type_annotations_offset,      k, vmSymbols::type_annotations_name(),      vmSymbols::byte_array_signature());
2485 }
2486 
2487 Handle java_lang_reflect_Constructor::create(TRAPS) {
2488   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2489   Symbol* name = vmSymbols::java_lang_reflect_Constructor();
2490   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2491   InstanceKlass* ik = InstanceKlass::cast(k);
2492   // Ensure it is initialized
2493   ik->initialize(CHECK_NH);
2494   return ik->allocate_instance_handle(THREAD);
2495 }
2496 
2497 oop java_lang_reflect_Constructor::clazz(oop reflect) {
2498   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2499   return reflect->obj_field(clazz_offset);
2500 }
2501 
2502 void java_lang_reflect_Constructor::set_clazz(oop reflect, oop value) {
2503   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2504    reflect->obj_field_put(clazz_offset, value);
2505 }
2506 
2507 oop java_lang_reflect_Constructor::parameter_types(oop constructor) {
2508   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2509   return constructor->obj_field(parameterTypes_offset);
2510 }
2511 
2512 void java_lang_reflect_Constructor::set_parameter_types(oop constructor, oop value) {
2513   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2514   constructor->obj_field_put(parameterTypes_offset, value);


2611 void java_lang_reflect_Field::compute_offsets() {
2612   Klass* k = SystemDictionary::reflect_Field_klass();
2613   compute_offset(clazz_offset,     k, vmSymbols::clazz_name(),     vmSymbols::class_signature());
2614   compute_offset(name_offset,      k, vmSymbols::name_name(),      vmSymbols::string_signature());
2615   compute_offset(type_offset,      k, vmSymbols::type_name(),      vmSymbols::class_signature());
2616   compute_offset(slot_offset,      k, vmSymbols::slot_name(),      vmSymbols::int_signature());
2617   compute_offset(modifiers_offset, k, vmSymbols::modifiers_name(), vmSymbols::int_signature());
2618   // The generic signature and annotations fields are only present in 1.5
2619   signature_offset = -1;
2620   annotations_offset = -1;
2621   type_annotations_offset = -1;
2622   compute_optional_offset(signature_offset, k, vmSymbols::signature_name(), vmSymbols::string_signature());
2623   compute_optional_offset(annotations_offset,  k, vmSymbols::annotations_name(),  vmSymbols::byte_array_signature());
2624   compute_optional_offset(type_annotations_offset,  k, vmSymbols::type_annotations_name(),  vmSymbols::byte_array_signature());
2625 }
2626 
2627 Handle java_lang_reflect_Field::create(TRAPS) {
2628   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2629   Symbol* name = vmSymbols::java_lang_reflect_Field();
2630   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2631   InstanceKlass* ik = InstanceKlass::cast(k);
2632   // Ensure it is initialized
2633   ik->initialize(CHECK_NH);
2634   return ik->allocate_instance_handle(THREAD);
2635 }
2636 
2637 oop java_lang_reflect_Field::clazz(oop reflect) {
2638   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2639   return reflect->obj_field(clazz_offset);
2640 }
2641 
2642 void java_lang_reflect_Field::set_clazz(oop reflect, oop value) {
2643   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2644    reflect->obj_field_put(clazz_offset, value);
2645 }
2646 
2647 oop java_lang_reflect_Field::name(oop field) {
2648   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2649   return field->obj_field(name_offset);
2650 }
2651 
2652 void java_lang_reflect_Field::set_name(oop field, oop value) {
2653   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2654   field->obj_field_put(name_offset, value);


2738   if (k != NULL) {
2739     // The field is called ConstantPool* in the sun.reflect.ConstantPool class.
2740     compute_offset(_oop_offset, k, vmSymbols::ConstantPool_name(), vmSymbols::object_signature());
2741   }
2742 }
2743 
2744 void java_lang_reflect_Parameter::compute_offsets() {
2745   Klass* k = SystemDictionary::reflect_Parameter_klass();
2746   if(NULL != k) {
2747     compute_offset(name_offset,        k, vmSymbols::name_name(),        vmSymbols::string_signature());
2748     compute_offset(modifiers_offset,   k, vmSymbols::modifiers_name(),   vmSymbols::int_signature());
2749     compute_offset(index_offset,       k, vmSymbols::index_name(),       vmSymbols::int_signature());
2750     compute_offset(executable_offset,  k, vmSymbols::executable_name(),  vmSymbols::executable_signature());
2751   }
2752 }
2753 
2754 Handle java_lang_reflect_Parameter::create(TRAPS) {
2755   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2756   Symbol* name = vmSymbols::java_lang_reflect_Parameter();
2757   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2758   InstanceKlass* ik = InstanceKlass::cast(k);
2759   // Ensure it is initialized
2760   ik->initialize(CHECK_NH);
2761   return ik->allocate_instance_handle(THREAD);
2762 }
2763 
2764 oop java_lang_reflect_Parameter::name(oop param) {
2765   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2766   return param->obj_field(name_offset);
2767 }
2768 
2769 void java_lang_reflect_Parameter::set_name(oop param, oop value) {
2770   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2771   param->obj_field_put(name_offset, value);
2772 }
2773 
2774 int java_lang_reflect_Parameter::modifiers(oop param) {
2775   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2776   return param->int_field(modifiers_offset);
2777 }
2778 
2779 void java_lang_reflect_Parameter::set_modifiers(oop param, int value) {
2780   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2781   param->int_field_put(modifiers_offset, value);


2794 oop java_lang_reflect_Parameter::executable(oop param) {
2795   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2796   return param->obj_field(executable_offset);
2797 }
2798 
2799 void java_lang_reflect_Parameter::set_executable(oop param, oop value) {
2800   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2801   param->obj_field_put(executable_offset, value);
2802 }
2803 
2804 
2805 int java_lang_reflect_Module::loader_offset;
2806 int java_lang_reflect_Module::name_offset;
2807 int java_lang_reflect_Module::_module_entry_offset = -1;
2808 
2809 Handle java_lang_reflect_Module::create(Handle loader, Handle module_name, TRAPS) {
2810   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2811 
2812   Symbol* name = vmSymbols::java_lang_reflect_Module();
2813   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
2814   InstanceKlass* ik = InstanceKlass::cast(k);
2815   Handle jlrmh = ik->allocate_instance_handle(CHECK_NH);

2816   JavaValue result(T_VOID);
2817   JavaCalls::call_special(&result, jlrmh, ik,
2818                           vmSymbols::object_initializer_name(),
2819                           vmSymbols::java_lang_reflect_module_init_signature(),
2820                           loader, module_name, CHECK_NH);
2821   return jlrmh;
2822 }
2823 
2824 void java_lang_reflect_Module::compute_offsets() {
2825   Klass* k = SystemDictionary::reflect_Module_klass();
2826   if(NULL != k) {
2827     compute_offset(loader_offset,  k, vmSymbols::loader_name(),  vmSymbols::classloader_signature());
2828     compute_offset(name_offset,    k, vmSymbols::name_name(),    vmSymbols::string_signature());
2829     MODULE_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
2830   }
2831 }
2832 
2833 
2834 oop java_lang_reflect_Module::loader(oop module) {
2835   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2836   return module->obj_field(loader_offset);
2837 }


2860   if (module_entry == NULL) {
2861     // If the inject field containing the ModuleEntry* is null then return the
2862     // class loader's unnamed module.
2863     oop loader = java_lang_reflect_Module::loader(module);
2864     Handle h_loader = Handle(THREAD, loader);
2865     ClassLoaderData* loader_cld = SystemDictionary::register_loader(h_loader, CHECK_NULL);
2866     return loader_cld->modules()->unnamed_module();
2867   }
2868   return module_entry;
2869 }
2870 
2871 void java_lang_reflect_Module::set_module_entry(oop module, ModuleEntry* module_entry) {
2872   assert(_module_entry_offset != -1, "Uninitialized module_entry_offset");
2873   assert(module != NULL, "module can't be null");
2874   assert(module->is_oop(), "module must be oop");
2875   module->address_field_put(_module_entry_offset, (address)module_entry);
2876 }
2877 
2878 Handle reflect_ConstantPool::create(TRAPS) {
2879   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2880   InstanceKlass* k = SystemDictionary::reflect_ConstantPool_klass();

2881   // Ensure it is initialized
2882   k->initialize(CHECK_NH);
2883   return k->allocate_instance_handle(THREAD);
2884 }
2885 
2886 
2887 void reflect_ConstantPool::set_cp(oop reflect, ConstantPool* value) {
2888   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2889   oop mirror = value->pool_holder()->java_mirror();
2890   // Save the mirror to get back the constant pool.
2891   reflect->obj_field_put(_oop_offset, mirror);
2892 }
2893 
2894 ConstantPool* reflect_ConstantPool::get_cp(oop reflect) {
2895   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
2896 
2897   oop mirror = reflect->obj_field(_oop_offset);
2898   Klass* k = java_lang_Class::as_Klass(mirror);
2899   assert(k->is_instance_klass(), "Must be");
2900 
2901   // Get the constant pool back from the klass.  Since class redefinition
2902   // merges the new constant pool into the old, this is essentially the
2903   // same constant pool as the original.  If constant pool merging is
2904   // no longer done in the future, this will have to change to save
2905   // the original.
2906   return InstanceKlass::cast(k)->constants();
2907 }
2908 
2909 void reflect_UnsafeStaticFieldAccessorImpl::compute_offsets() {
2910   Klass* k = SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass();
2911   // This null test can be removed post beta
2912   if (k != NULL) {
2913     compute_offset(_base_offset, k,
2914                    vmSymbols::base_name(), vmSymbols::object_signature());
2915   }
2916 }
2917 
2918 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
2919   Klass* k = SystemDictionary::box_klass(type);
2920   if (k == NULL)  return NULL;
2921   InstanceKlass* ik = InstanceKlass::cast(k);
2922   if (!ik->is_initialized())  ik->initialize(CHECK_0);
2923   return ik->allocate_instance(THREAD);
2924 }
2925 
2926 
2927 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) {
2928   oop box = initialize_and_allocate(type, CHECK_0);
2929   if (box == NULL)  return NULL;
2930   switch (type) {
2931     case T_BOOLEAN:
2932       box->bool_field_put(value_offset, value->z);
2933       break;
2934     case T_CHAR:
2935       box->char_field_put(value_offset, value->c);
2936       break;
2937     case T_FLOAT:
2938       box->float_field_put(value_offset, value->f);
2939       break;
2940     case T_DOUBLE:
2941       box->double_field_put(long_value_offset, value->d);
2942       break;
2943     case T_BYTE:


3865   reflect_UnsafeStaticFieldAccessorImpl::compute_offsets();
3866   java_lang_reflect_Parameter::compute_offsets();
3867   java_lang_reflect_Module::compute_offsets();
3868   java_lang_StackFrameInfo::compute_offsets();
3869   java_lang_LiveStackFrameInfo::compute_offsets();
3870 
3871   // generated interpreter code wants to know about the offsets we just computed:
3872   AbstractAssembler::update_delayed_values();
3873 }
3874 
3875 #ifndef PRODUCT
3876 
3877 // These functions exist to assert the validity of hard-coded field offsets to guard
3878 // against changes in the class files
3879 
3880 bool JavaClasses::check_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
3881   EXCEPTION_MARK;
3882   fieldDescriptor fd;
3883   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
3884   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
3885   InstanceKlass* ik = InstanceKlass::cast(k);
3886   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
3887   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
3888   if (!ik->find_local_field(f_name, f_sig, &fd)) {
3889     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
3890     return false;
3891   }
3892   if (fd.is_static()) {
3893     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
3894     return false;
3895   }
3896   if (fd.offset() == hardcoded_offset ) {
3897     return true;
3898   } else {
3899     tty->print_cr("Offset of nonstatic field %s.%s is hardcoded as %d but should really be %d.",
3900                   klass_name, field_name, hardcoded_offset, fd.offset());
3901     return false;
3902   }
3903 }
3904 
3905 
3906 bool JavaClasses::check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) {
3907   EXCEPTION_MARK;
3908   fieldDescriptor fd;
3909   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
3910   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
3911   InstanceKlass* ik = InstanceKlass::cast(k);
3912   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
3913   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
3914   if (!ik->find_local_field(f_name, f_sig, &fd)) {
3915     tty->print_cr("Static field %s.%s not found", klass_name, field_name);
3916     return false;
3917   }
3918   if (!fd.is_static()) {
3919     tty->print_cr("Static field %s.%s appears to be nonstatic", klass_name, field_name);
3920     return false;
3921   }
3922   if (fd.offset() == hardcoded_offset + InstanceMirrorKlass::offset_of_static_fields()) {
3923     return true;
3924   } else {
3925     tty->print_cr("Offset of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_offset, fd.offset() - InstanceMirrorKlass::offset_of_static_fields());
3926     return false;
3927   }
3928 }
3929 
3930 
3931 bool JavaClasses::check_constant(const char *klass_name, int hardcoded_constant, const char *field_name, const char* field_sig) {
3932   EXCEPTION_MARK;
3933   fieldDescriptor fd;
3934   TempNewSymbol klass_sym = SymbolTable::new_symbol(klass_name, CATCH);
3935   Klass* k = SystemDictionary::resolve_or_fail(klass_sym, true, CATCH);
3936   InstanceKlass* ik = InstanceKlass::cast(k);
3937   TempNewSymbol f_name = SymbolTable::new_symbol(field_name, CATCH);
3938   TempNewSymbol f_sig  = SymbolTable::new_symbol(field_sig, CATCH);
3939   if (!ik->find_local_field(f_name, f_sig, &fd)) {
3940     tty->print_cr("Static field %s.%s not found", klass_name, field_name);
3941     return false;
3942   }
3943   if (!fd.is_static() || !fd.has_initial_value()) {
3944     tty->print_cr("Static field %s.%s appears to be non-constant", klass_name, field_name);
3945     return false;
3946   }
3947   if (!fd.initial_value_tag().is_int()) {
3948     tty->print_cr("Static field %s.%s is not an int", klass_name, field_name);
3949     return false;
3950   }
3951   jint field_value = fd.int_initial_value();
3952   if (field_value == hardcoded_constant) {
3953     return true;
3954   } else {
3955     tty->print_cr("Constant value of static field %s.%s is hardcoded as %d but should really be %d.", klass_name, field_name, hardcoded_constant, field_value);
3956     return false;
3957   }
3958 }
3959 


< prev index next >