src/share/vm/oops/instanceKlass.cpp

Print this page




1115   // Retry lookup after we got the lock
1116   JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset);
1117   if (probe == NULL) {
1118     // Slow case, allocate new static field identifier
1119     probe = new JNIid(this_oop->as_klassOop(), offset, this_oop->jni_ids());
1120     this_oop->set_jni_ids(probe);
1121   }
1122   return probe;
1123 }
1124 
1125 
1126 /* jni_id_for for jfieldIds only */
1127 JNIid* instanceKlass::jni_id_for(int offset) {
1128   JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset);
1129   if (probe == NULL) {
1130     probe = jni_id_for_impl(this->as_klassOop(), offset);
1131   }
1132   return probe;
1133 }
1134 
































1135 
1136 // Lookup or create a jmethodID.
1137 // This code is called by the VMThread and JavaThreads so the
1138 // locking has to be done very carefully to avoid deadlocks
1139 // and/or other cache consistency problems.
1140 //
1141 jmethodID instanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) {
1142   size_t idnum = (size_t)method_h->method_idnum();
1143   jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire();
1144   size_t length = 0;
1145   jmethodID id = NULL;
1146 
1147   // We use a double-check locking idiom here because this cache is
1148   // performance sensitive. In the normal system, this cache only
1149   // transitions from NULL to non-NULL which is safe because we use
1150   // release_set_methods_jmethod_ids() to advertise the new cache.
1151   // A partially constructed cache should never be seen by a racing
1152   // thread. We also use release_store_ptr() to save a new jmethodID
1153   // in the cache so a partially constructed jmethodID should never be
1154   // seen either. Cache reads of existing jmethodIDs proceed without a


2091     if (next == NULL)  break;
2092     // Might as well check the new outer against all available values.
2093     if (next == class1())  return true;
2094     if (next == outer1())  return true;
2095     outer2 = instanceKlassHandle(THREAD, next);
2096   }
2097 
2098   // If by this point we have not found an equality between the
2099   // two classes, we know they are in separate package members.
2100   return false;
2101 }
2102 
2103 
2104 jint instanceKlass::compute_modifier_flags(TRAPS) const {
2105   klassOop k = as_klassOop();
2106   jint access = access_flags().as_int();
2107 
2108   // But check if it happens to be member class.
2109   typeArrayOop inner_class_list = inner_classes();
2110   int length = (inner_class_list == NULL) ? 0 : inner_class_list->length();
2111   assert (length % instanceKlass::inner_class_next_offset == 0, "just checking");


2112   if (length > 0) {
2113     typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
2114     instanceKlassHandle ik(THREAD, k);
2115     for (int i = 0; i < length; i += instanceKlass::inner_class_next_offset) {



2116       int ioff = inner_class_list_h->ushort_at(
2117                       i + instanceKlass::inner_class_inner_class_info_offset);
2118 
2119       // Inner class attribute can be zero, skip it.
2120       // Strange but true:  JVM spec. allows null inner class refs.
2121       if (ioff == 0) continue;
2122 
2123       // only look at classes that are already loaded
2124       // since we are looking for the flags for our self.
2125       Symbol* inner_name = ik->constants()->klass_name_at(ioff);
2126       if ((ik->name() == inner_name)) {
2127         // This is really a member class.
2128         access = inner_class_list_h->ushort_at(i + instanceKlass::inner_class_access_flags_offset);
2129         break;
2130       }
2131     }
2132   }
2133   // Remember to strip ACC_SUPER bit
2134   return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
2135 }




1115   // Retry lookup after we got the lock
1116   JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset);
1117   if (probe == NULL) {
1118     // Slow case, allocate new static field identifier
1119     probe = new JNIid(this_oop->as_klassOop(), offset, this_oop->jni_ids());
1120     this_oop->set_jni_ids(probe);
1121   }
1122   return probe;
1123 }
1124 
1125 
1126 /* jni_id_for for jfieldIds only */
1127 JNIid* instanceKlass::jni_id_for(int offset) {
1128   JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset);
1129   if (probe == NULL) {
1130     probe = jni_id_for_impl(this->as_klassOop(), offset);
1131   }
1132   return probe;
1133 }
1134 
1135 u2 instanceKlass::enclosing_method_data(int offset) {
1136   typeArrayOop inner_class_list = inner_classes();
1137   if (inner_class_list == NULL) {
1138     return 0;
1139   }
1140   int length = inner_class_list->length();
1141   if (length % inner_class_next_offset == 0) {
1142     return 0;
1143   } else {
1144     EXCEPTION_MARK;
1145     int index = length - enclosing_method_attribute_size;
1146     typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
1147     assert(offset < enclosing_method_attribute_size, "invalid offset");
1148     return inner_class_list_h->ushort_at(index + offset);
1149   }
1150 }
1151 
1152 void instanceKlass::set_enclosing_method_indices(u2 class_index,
1153                                                  u2 method_index) {
1154   EXCEPTION_MARK;
1155   typeArrayOop inner_class_list = inner_classes();
1156   assert (inner_class_list != NULL, "_inner_classes list is not set up");
1157   int length = inner_class_list->length();
1158   assert (length % inner_class_next_offset == enclosing_method_attribute_size,
1159           "Incorrect _inner_classes array length");
1160   int index = length - enclosing_method_attribute_size;
1161   typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
1162   inner_class_list_h->ushort_at_put(
1163     index + enclosing_method_class_index_offset, class_index);
1164   inner_class_list_h->ushort_at_put(
1165     index + enclosing_method_method_index_offset, method_index);
1166 }
1167 
1168 // Lookup or create a jmethodID.
1169 // This code is called by the VMThread and JavaThreads so the
1170 // locking has to be done very carefully to avoid deadlocks
1171 // and/or other cache consistency problems.
1172 //
1173 jmethodID instanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) {
1174   size_t idnum = (size_t)method_h->method_idnum();
1175   jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire();
1176   size_t length = 0;
1177   jmethodID id = NULL;
1178 
1179   // We use a double-check locking idiom here because this cache is
1180   // performance sensitive. In the normal system, this cache only
1181   // transitions from NULL to non-NULL which is safe because we use
1182   // release_set_methods_jmethod_ids() to advertise the new cache.
1183   // A partially constructed cache should never be seen by a racing
1184   // thread. We also use release_store_ptr() to save a new jmethodID
1185   // in the cache so a partially constructed jmethodID should never be
1186   // seen either. Cache reads of existing jmethodIDs proceed without a


2123     if (next == NULL)  break;
2124     // Might as well check the new outer against all available values.
2125     if (next == class1())  return true;
2126     if (next == outer1())  return true;
2127     outer2 = instanceKlassHandle(THREAD, next);
2128   }
2129 
2130   // If by this point we have not found an equality between the
2131   // two classes, we know they are in separate package members.
2132   return false;
2133 }
2134 
2135 
2136 jint instanceKlass::compute_modifier_flags(TRAPS) const {
2137   klassOop k = as_klassOop();
2138   jint access = access_flags().as_int();
2139 
2140   // But check if it happens to be member class.
2141   typeArrayOop inner_class_list = inner_classes();
2142   int length = (inner_class_list == NULL) ? 0 : inner_class_list->length();
2143   assert ((length % instanceKlass::inner_class_next_offset == 0 ||
2144            length % instanceKlass::inner_class_next_offset == instanceKlass::enclosing_method_attribute_size),
2145            "just checking");
2146   if (length > 0) {
2147     typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
2148     instanceKlassHandle ik(THREAD, k);
2149     for (int i = 0; i < length; i += instanceKlass::inner_class_next_offset) {
2150       if (i == length - instanceKlass::enclosing_method_attribute_size) {
2151         break;
2152       }
2153       int ioff = inner_class_list_h->ushort_at(
2154                       i + instanceKlass::inner_class_inner_class_info_offset);
2155 
2156       // Inner class attribute can be zero, skip it.
2157       // Strange but true:  JVM spec. allows null inner class refs.
2158       if (ioff == 0) continue;
2159 
2160       // only look at classes that are already loaded
2161       // since we are looking for the flags for our self.
2162       Symbol* inner_name = ik->constants()->klass_name_at(ioff);
2163       if ((ik->name() == inner_name)) {
2164         // This is really a member class.
2165         access = inner_class_list_h->ushort_at(i + instanceKlass::inner_class_access_flags_offset);
2166         break;
2167       }
2168     }
2169   }
2170   // Remember to strip ACC_SUPER bit
2171   return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
2172 }