1970 // --> see ArrayKlass::complete_create_array_klass() |
1970 // --> see ArrayKlass::complete_create_array_klass() |
1971 k->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK); |
1971 k->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK); |
1972 } |
1972 } |
1973 |
1973 |
1974 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { |
1974 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { |
|
1975 instanceKlassHandle ik(THREAD, this); |
|
1976 ik->set_package(loader_data, CHECK); |
1975 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK); |
1977 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK); |
1976 instanceKlassHandle ik(THREAD, this); |
|
1977 |
1978 |
1978 Array<Method*>* methods = ik->methods(); |
1979 Array<Method*>* methods = ik->methods(); |
1979 int num_methods = methods->length(); |
1980 int num_methods = methods->length(); |
1980 for (int index2 = 0; index2 < num_methods; ++index2) { |
1981 for (int index2 = 0; index2 < num_methods; ++index2) { |
1981 methodHandle m(THREAD, methods->at(index2)); |
1982 methodHandle m(THREAD, methods->at(index2)); |
2176 dest[dest_index++] = ';'; |
2177 dest[dest_index++] = ';'; |
2177 dest[dest_index] = '\0'; |
2178 dest[dest_index] = '\0'; |
2178 return dest; |
2179 return dest; |
2179 } |
2180 } |
2180 |
2181 |
2181 // different verisons of is_same_class_package |
2182 const jbyte* InstanceKlass::package_from_name(const Symbol* name, int& length) { |
|
2183 ResourceMark rm; |
|
2184 length = 0; |
|
2185 if (name == NULL) { |
|
2186 return NULL; |
|
2187 } else { |
|
2188 const jbyte* base_name = name->base(); |
|
2189 const jbyte* last_slash = UTF8::strrchr(base_name, name->utf8_length(), '/'); |
|
2190 |
|
2191 if (last_slash == NULL) { |
|
2192 // No package name |
|
2193 return NULL; |
|
2194 } else { |
|
2195 // Skip over '['s |
|
2196 if (*base_name == '[') { |
|
2197 do { |
|
2198 base_name++; |
|
2199 } while (*base_name == '['); |
|
2200 if (*base_name != 'L') { |
|
2201 // Fully qualified class names should not contain a 'L'. |
|
2202 // Set length to -1 to indicate that the package name |
|
2203 // could not be obtained due to an error condition. |
|
2204 // In this situtation, is_same_class_package returns false. |
|
2205 length = -1; |
|
2206 return NULL; |
|
2207 } |
|
2208 } |
|
2209 |
|
2210 // Found the package name, look it up in the symbol table. |
|
2211 length = last_slash - base_name; |
|
2212 assert(length > 0, "Bad length for package name"); |
|
2213 return base_name; |
|
2214 } |
|
2215 } |
|
2216 } |
|
2217 |
|
2218 ModuleEntry* InstanceKlass::module() const { |
|
2219 if (!in_unnamed_package()) { |
|
2220 return _package_entry->module(); |
|
2221 } |
|
2222 const Klass* host = host_klass(); |
|
2223 if (host == NULL) { |
|
2224 return class_loader_data()->modules()->unnamed_module(); |
|
2225 } |
|
2226 return host->class_loader_data()->modules()->unnamed_module(); |
|
2227 } |
|
2228 |
|
2229 void InstanceKlass::set_package(ClassLoaderData* loader_data, TRAPS) { |
|
2230 int length = 0; |
|
2231 const jbyte* base_name = package_from_name(name(), length); |
|
2232 |
|
2233 if (base_name != NULL && loader_data != NULL) { |
|
2234 TempNewSymbol pkg_name = SymbolTable::new_symbol((const char*)base_name, length, CHECK); |
|
2235 |
|
2236 // Find in class loader's package entry table. |
|
2237 _package_entry = loader_data->packages()->lookup_only(pkg_name); |
|
2238 |
|
2239 // If the package name is not found in the loader's package |
|
2240 // entry table, it is an indication that the package has not |
|
2241 // been defined. Consider it defined within the unnamed module. |
|
2242 if (_package_entry == NULL) { |
|
2243 ResourceMark rm; |
|
2244 |
|
2245 if (!ModuleEntryTable::javabase_defined()) { |
|
2246 // Before java.base is defined during bootstrapping, define all packages in |
|
2247 // the java.base module. If a non-java.base package is erroneously placed |
|
2248 // in the java.base module it will be caught later when java.base |
|
2249 // is defined by ModuleEntryTable::verify_javabase_packages check. |
|
2250 assert(ModuleEntryTable::javabase_module() != NULL, "java.base module is NULL"); |
|
2251 _package_entry = loader_data->packages()->lookup(pkg_name, ModuleEntryTable::javabase_module()); |
|
2252 } else { |
|
2253 assert(loader_data->modules()->unnamed_module() != NULL, "unnamed module is NULL"); |
|
2254 _package_entry = loader_data->packages()->lookup(pkg_name, |
|
2255 loader_data->modules()->unnamed_module()); |
|
2256 } |
|
2257 |
|
2258 // A package should have been successfully created |
|
2259 assert(_package_entry != NULL, "Package entry for class %s not found, loader %s", |
|
2260 name()->as_C_string(), loader_data->loader_name()); |
|
2261 } |
|
2262 |
|
2263 if (log_is_enabled(Debug, modules)) { |
|
2264 ResourceMark rm; |
|
2265 ModuleEntry* m = _package_entry->module(); |
|
2266 log_trace(modules)("Setting package: class: %s, package: %s, loader: %s, module: %s", |
|
2267 external_name(), |
|
2268 pkg_name->as_C_string(), |
|
2269 loader_data->loader_name(), |
|
2270 (m->is_named() ? m->name()->as_C_string() : UNNAMED_MODULE)); |
|
2271 } |
|
2272 } else { |
|
2273 ResourceMark rm; |
|
2274 log_trace(modules)("Setting package: class: %s, package: unnamed, loader: %s, module: %s", |
|
2275 external_name(), |
|
2276 (loader_data != NULL) ? loader_data->loader_name() : "NULL", |
|
2277 UNNAMED_MODULE); |
|
2278 } |
|
2279 } |
|
2280 |
|
2281 |
|
2282 // different versions of is_same_class_package |
|
2283 |
2182 bool InstanceKlass::is_same_class_package(const Klass* class2) const { |
2284 bool InstanceKlass::is_same_class_package(const Klass* class2) const { |
2183 const Klass* const class1 = (const Klass* const)this; |
2285 oop classloader1 = this->class_loader(); |
2184 oop classloader1 = InstanceKlass::cast(class1)->class_loader(); |
2286 PackageEntry* classpkg1 = this->package(); |
2185 const Symbol* const classname1 = class1->name(); |
|
2186 |
|
2187 if (class2->is_objArray_klass()) { |
2287 if (class2->is_objArray_klass()) { |
2188 class2 = ObjArrayKlass::cast(class2)->bottom_klass(); |
2288 class2 = ObjArrayKlass::cast(class2)->bottom_klass(); |
2189 } |
2289 } |
|
2290 |
2190 oop classloader2; |
2291 oop classloader2; |
|
2292 PackageEntry* classpkg2; |
2191 if (class2->is_instance_klass()) { |
2293 if (class2->is_instance_klass()) { |
2192 classloader2 = InstanceKlass::cast(class2)->class_loader(); |
2294 classloader2 = class2->class_loader(); |
|
2295 classpkg2 = InstanceKlass::cast(class2)->package(); |
2193 } else { |
2296 } else { |
2194 assert(class2->is_typeArray_klass(), "should be type array"); |
2297 assert(class2->is_typeArray_klass(), "should be type array"); |
2195 classloader2 = NULL; |
2298 classloader2 = NULL; |
2196 } |
2299 classpkg2 = NULL; |
2197 const Symbol* classname2 = class2->name(); |
2300 } |
2198 |
2301 |
2199 return InstanceKlass::is_same_class_package(classloader1, classname1, |
2302 // Same package is determined by comparing class loader |
2200 classloader2, classname2); |
2303 // and package entries. Both must be the same. This rule |
|
2304 // applies even to classes that are defined in the unnamed |
|
2305 // package, they still must have the same class loader. |
|
2306 if ((classloader1 == classloader2) && (classpkg1 == classpkg2)) { |
|
2307 return true; |
|
2308 } |
|
2309 |
|
2310 return false; |
2201 } |
2311 } |
2202 |
2312 |
2203 bool InstanceKlass::is_same_class_package(oop other_class_loader, |
2313 bool InstanceKlass::is_same_class_package(oop other_class_loader, |
2204 const Symbol* other_class_name) const { |
2314 const Symbol* other_class_name) const { |
2205 oop this_class_loader = class_loader(); |
2315 oop this_class_loader = class_loader(); |
2223 ResourceMark rm; |
2333 ResourceMark rm; |
2224 |
2334 |
2225 // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly |
2335 // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly |
2226 // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding. |
2336 // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding. |
2227 // Otherwise, we just compare jbyte values between the strings. |
2337 // Otherwise, we just compare jbyte values between the strings. |
2228 const jbyte *name1 = class_name1->base(); |
2338 int length1 = 0; |
2229 const jbyte *name2 = class_name2->base(); |
2339 int length2 = 0; |
2230 |
2340 const jbyte *name1 = package_from_name(class_name1, length1); |
2231 const jbyte *last_slash1 = UTF8::strrchr(name1, class_name1->utf8_length(), '/'); |
2341 const jbyte *name2 = package_from_name(class_name2, length2); |
2232 const jbyte *last_slash2 = UTF8::strrchr(name2, class_name2->utf8_length(), '/'); |
2342 |
2233 |
2343 if ((length1 < 0) || (length2 < 0)) { |
2234 if ((last_slash1 == NULL) || (last_slash2 == NULL)) { |
2344 // error occurred parsing package name. |
|
2345 return false; |
|
2346 } |
|
2347 |
|
2348 if ((name1 == NULL) || (name2 == NULL)) { |
2235 // One of the two doesn't have a package. Only return true |
2349 // One of the two doesn't have a package. Only return true |
2236 // if the other one also doesn't have a package. |
2350 // if the other one also doesn't have a package. |
2237 return last_slash1 == last_slash2; |
2351 return name1 == name2; |
2238 } else { |
2352 } |
2239 // Skip over '['s |
2353 |
2240 if (*name1 == '[') { |
2354 // Check that package part is identical |
2241 do { |
2355 return UTF8::equal(name1, length1, name2, length2); |
2242 name1++; |
|
2243 } while (*name1 == '['); |
|
2244 if (*name1 != 'L') { |
|
2245 // Something is terribly wrong. Shouldn't be here. |
|
2246 return false; |
|
2247 } |
|
2248 } |
|
2249 if (*name2 == '[') { |
|
2250 do { |
|
2251 name2++; |
|
2252 } while (*name2 == '['); |
|
2253 if (*name2 != 'L') { |
|
2254 // Something is terribly wrong. Shouldn't be here. |
|
2255 return false; |
|
2256 } |
|
2257 } |
|
2258 |
|
2259 // Check that package part is identical |
|
2260 int length1 = last_slash1 - name1; |
|
2261 int length2 = last_slash2 - name2; |
|
2262 |
|
2263 return UTF8::equal(name1, length1, name2, length2); |
|
2264 } |
|
2265 } |
2356 } |
2266 } |
2357 } |
2267 |
2358 |
2268 // Returns true iff super_method can be overridden by a method in targetclassname |
2359 // Returns true iff super_method can be overridden by a method in targetclassname |
2269 // See JSL 3rd edition 8.4.6.1 |
2360 // See JSL 3rd edition 8.4.6.1 |