comparison src/share/vm/oops/instanceKlass.cpp @ 3938:e6b1331a51d2

7086585: make Java field injection more flexible Reviewed-by: jrose, twisti, kvn, coleenp
author never
date Sat, 10 Sep 2011 17:29:02 -0700
parents fdb992d83a87
children f6f3bb0ee072
comparison
equal deleted inserted replaced
3937:c565834fb592 3938:e6b1331a51d2
34 #include "interpreter/rewriter.hpp" 34 #include "interpreter/rewriter.hpp"
35 #include "jvmtifiles/jvmti.h" 35 #include "jvmtifiles/jvmti.h"
36 #include "memory/genOopClosures.inline.hpp" 36 #include "memory/genOopClosures.inline.hpp"
37 #include "memory/oopFactory.hpp" 37 #include "memory/oopFactory.hpp"
38 #include "memory/permGen.hpp" 38 #include "memory/permGen.hpp"
39 #include "oops/fieldStreams.hpp"
39 #include "oops/instanceKlass.hpp" 40 #include "oops/instanceKlass.hpp"
40 #include "oops/instanceMirrorKlass.hpp" 41 #include "oops/instanceMirrorKlass.hpp"
41 #include "oops/instanceOop.hpp" 42 #include "oops/instanceOop.hpp"
42 #include "oops/methodOop.hpp" 43 #include "oops/methodOop.hpp"
43 #include "oops/objArrayKlassKlass.hpp" 44 #include "oops/objArrayKlassKlass.hpp"
780 _oop_map_cache->lookup(method, bci, entry_for); 781 _oop_map_cache->lookup(method, bci, entry_for);
781 } 782 }
782 783
783 784
784 bool instanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { 785 bool instanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
785 const int n = fields()->length(); 786 for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) {
786 for (int i = 0; i < n; i += next_offset ) { 787 Symbol* f_name = fs.name();
787 int name_index = fields()->ushort_at(i + name_index_offset); 788 Symbol* f_sig = fs.signature();
788 int sig_index = fields()->ushort_at(i + signature_index_offset);
789 Symbol* f_name = constants()->symbol_at(name_index);
790 Symbol* f_sig = constants()->symbol_at(sig_index);
791 if (f_name == name && f_sig == sig) { 789 if (f_name == name && f_sig == sig) {
792 fd->initialize(as_klassOop(), i); 790 fd->initialize(as_klassOop(), fs.index());
793 return true; 791 return true;
794 } 792 }
795 } 793 }
796 return false; 794 return false;
797 } 795 }
801 Klass::shared_symbols_iterate(closure); 799 Klass::shared_symbols_iterate(closure);
802 closure->do_symbol(&_generic_signature); 800 closure->do_symbol(&_generic_signature);
803 closure->do_symbol(&_source_file_name); 801 closure->do_symbol(&_source_file_name);
804 closure->do_symbol(&_source_debug_extension); 802 closure->do_symbol(&_source_debug_extension);
805 803
806 const int n = fields()->length(); 804 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
807 for (int i = 0; i < n; i += next_offset ) { 805 int name_index = fs.name_index();
808 int name_index = fields()->ushort_at(i + name_index_offset);
809 closure->do_symbol(constants()->symbol_at_addr(name_index)); 806 closure->do_symbol(constants()->symbol_at_addr(name_index));
810 int sig_index = fields()->ushort_at(i + signature_index_offset); 807 int sig_index = fs.signature_index();
811 closure->do_symbol(constants()->symbol_at_addr(sig_index)); 808 closure->do_symbol(constants()->symbol_at_addr(sig_index));
812 } 809 }
813 } 810 }
814 811
815 812
870 return NULL; 867 return NULL;
871 } 868 }
872 869
873 870
874 bool instanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { 871 bool instanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
875 int length = fields()->length(); 872 for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) {
876 for (int i = 0; i < length; i += next_offset) { 873 if (fs.offset() == offset) {
877 if (offset_from_fields( i ) == offset) { 874 fd->initialize(as_klassOop(), fs.index());
878 fd->initialize(as_klassOop(), i);
879 if (fd->is_static() == is_static) return true; 875 if (fd->is_static() == is_static) return true;
880 } 876 }
881 } 877 }
882 return false; 878 return false;
883 } 879 }
904 } 900 }
905 } 901 }
906 902
907 903
908 void instanceKlass::do_local_static_fields(FieldClosure* cl) { 904 void instanceKlass::do_local_static_fields(FieldClosure* cl) {
909 fieldDescriptor fd; 905 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
910 int length = fields()->length(); 906 if (fs.access_flags().is_static()) {
911 for (int i = 0; i < length; i += next_offset) { 907 fieldDescriptor fd;
912 fd.initialize(as_klassOop(), i); 908 fd.initialize(as_klassOop(), fs.index());
913 if (fd.is_static()) cl->do_field(&fd); 909 cl->do_field(&fd);
910 }
914 } 911 }
915 } 912 }
916 913
917 914
918 void instanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) { 915 void instanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) {
920 do_local_static_fields_impl(h_this, f, CHECK); 917 do_local_static_fields_impl(h_this, f, CHECK);
921 } 918 }
922 919
923 920
924 void instanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { 921 void instanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) {
925 fieldDescriptor fd; 922 for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) {
926 int length = this_oop->fields()->length(); 923 if (fs.access_flags().is_static()) {
927 for (int i = 0; i < length; i += next_offset) { 924 fieldDescriptor fd;
928 fd.initialize(this_oop(), i); 925 fd.initialize(this_oop(), fs.index());
929 if (fd.is_static()) { f(&fd, CHECK); } // Do NOT remove {}! (CHECK macro expands into several statements) 926 f(&fd, CHECK);
927 }
930 } 928 }
931 } 929 }
932 930
933 931
934 static int compare_fields_by_offset(int* a, int* b) { 932 static int compare_fields_by_offset(int* a, int* b) {
939 instanceKlass* super = superklass(); 937 instanceKlass* super = superklass();
940 if (super != NULL) { 938 if (super != NULL) {
941 super->do_nonstatic_fields(cl); 939 super->do_nonstatic_fields(cl);
942 } 940 }
943 fieldDescriptor fd; 941 fieldDescriptor fd;
944 int length = fields()->length(); 942 int length = java_fields_count();
945 // In DebugInfo nonstatic fields are sorted by offset. 943 // In DebugInfo nonstatic fields are sorted by offset.
946 int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1)); 944 int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1));
947 int j = 0; 945 int j = 0;
948 for (int i = 0; i < length; i += next_offset) { 946 for (int i = 0; i < length; i += 1) {
949 fd.initialize(as_klassOop(), i); 947 fd.initialize(as_klassOop(), i);
950 if (!fd.is_static()) { 948 if (!fd.is_static()) {
951 fields_sorted[j + 0] = fd.offset(); 949 fields_sorted[j + 0] = fd.offset();
952 fields_sorted[j + 1] = i; 950 fields_sorted[j + 1] = i;
953 j += 2; 951 j += 2;
2409 Klass::oop_verify_on(obj, st); 2407 Klass::oop_verify_on(obj, st);
2410 VerifyFieldClosure blk; 2408 VerifyFieldClosure blk;
2411 oop_oop_iterate(obj, &blk); 2409 oop_oop_iterate(obj, &blk);
2412 } 2410 }
2413 2411
2414 #ifndef PRODUCT
2415
2416 void instanceKlass::verify_class_klass_nonstatic_oop_maps(klassOop k) {
2417 // This verification code is disabled. JDK_Version::is_gte_jdk14x_version()
2418 // cannot be called since this function is called before the VM is
2419 // able to determine what JDK version is running with.
2420 // The check below always is false since 1.4.
2421 return;
2422
2423 // This verification code temporarily disabled for the 1.4
2424 // reflection implementation since java.lang.Class now has
2425 // Java-level instance fields. Should rewrite this to handle this
2426 // case.
2427 if (!(JDK_Version::is_gte_jdk14x_version() && UseNewReflection)) {
2428 // Verify that java.lang.Class instances have a fake oop field added.
2429 instanceKlass* ik = instanceKlass::cast(k);
2430
2431 // Check that we have the right class
2432 static bool first_time = true;
2433 guarantee(k == SystemDictionary::Class_klass() && first_time, "Invalid verify of maps");
2434 first_time = false;
2435 const int extra = java_lang_Class::number_of_fake_oop_fields;
2436 guarantee(ik->nonstatic_field_size() == extra, "just checking");
2437 guarantee(ik->nonstatic_oop_map_count() == 1, "just checking");
2438 guarantee(ik->size_helper() == align_object_size(instanceOopDesc::header_size() + extra), "just checking");
2439
2440 // Check that the map is (2,extra)
2441 int offset = java_lang_Class::klass_offset;
2442
2443 OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
2444 guarantee(map->offset() == offset && map->count() == (unsigned int) extra,
2445 "sanity");
2446 }
2447 }
2448
2449 #endif // ndef PRODUCT
2450
2451 // JNIid class for jfieldIDs only 2412 // JNIid class for jfieldIDs only
2452 // Note to reviewers: 2413 // Note to reviewers:
2453 // These JNI functions are just moved over to column 1 and not changed 2414 // These JNI functions are just moved over to column 1 and not changed
2454 // in the compressed oops workspace. 2415 // in the compressed oops workspace.
2455 JNIid::JNIid(klassOop holder, int offset, JNIid* next) { 2416 JNIid::JNIid(klassOop holder, int offset, JNIid* next) {