2180 dest[dest_index++] = ';'; |
2180 dest[dest_index++] = ';'; |
2181 dest[dest_index] = '\0'; |
2181 dest[dest_index] = '\0'; |
2182 return dest; |
2182 return dest; |
2183 } |
2183 } |
2184 |
2184 |
2185 const jbyte* InstanceKlass::package_from_name(const Symbol* name, int& length) { |
2185 // Used to obtain the package name from a fully qualified class name. |
2186 ResourceMark rm; |
2186 Symbol* InstanceKlass::package_from_name(const Symbol* name, TRAPS) { |
2187 length = 0; |
|
2188 if (name == NULL) { |
2187 if (name == NULL) { |
2189 return NULL; |
2188 return NULL; |
2190 } else { |
2189 } else { |
2191 const jbyte* base_name = name->base(); |
2190 if (name->utf8_length() <= 0) { |
2192 const jbyte* last_slash = UTF8::strrchr(base_name, name->utf8_length(), '/'); |
|
2193 |
|
2194 if (last_slash == NULL) { |
|
2195 // No package name |
|
2196 return NULL; |
2191 return NULL; |
2197 } else { |
2192 } |
2198 // Skip over '['s |
2193 ResourceMark rm; |
2199 if (*base_name == '[') { |
2194 const char* package_name = ClassLoader::package_from_name((const char*) name->as_C_string()); |
2200 do { |
2195 if (package_name == NULL) { |
2201 base_name++; |
2196 return NULL; |
2202 } while (*base_name == '['); |
2197 } |
2203 if (*base_name != 'L') { |
2198 Symbol* pkg_name = SymbolTable::new_symbol(package_name, THREAD); |
2204 // Fully qualified class names should not contain a 'L'. |
2199 return pkg_name; |
2205 // Set length to -1 to indicate that the package name |
|
2206 // could not be obtained due to an error condition. |
|
2207 // In this situtation, is_same_class_package returns false. |
|
2208 length = -1; |
|
2209 return NULL; |
|
2210 } |
|
2211 } |
|
2212 |
|
2213 // Found the package name, look it up in the symbol table. |
|
2214 length = last_slash - base_name; |
|
2215 assert(length > 0, "Bad length for package name"); |
|
2216 return base_name; |
|
2217 } |
|
2218 } |
2200 } |
2219 } |
2201 } |
2220 |
2202 |
2221 ModuleEntry* InstanceKlass::module() const { |
2203 ModuleEntry* InstanceKlass::module() const { |
2222 if (!in_unnamed_package()) { |
2204 if (!in_unnamed_package()) { |
2228 } |
2210 } |
2229 return host->class_loader_data()->modules()->unnamed_module(); |
2211 return host->class_loader_data()->modules()->unnamed_module(); |
2230 } |
2212 } |
2231 |
2213 |
2232 void InstanceKlass::set_package(ClassLoaderData* loader_data, TRAPS) { |
2214 void InstanceKlass::set_package(ClassLoaderData* loader_data, TRAPS) { |
2233 int length = 0; |
2215 TempNewSymbol pkg_name = package_from_name(name(), CHECK); |
2234 const jbyte* base_name = package_from_name(name(), length); |
2216 |
2235 |
2217 if (pkg_name != NULL && loader_data != NULL) { |
2236 if (base_name != NULL && loader_data != NULL) { |
|
2237 TempNewSymbol pkg_name = SymbolTable::new_symbol((const char*)base_name, length, CHECK); |
|
2238 |
|
2239 // Find in class loader's package entry table. |
2218 // Find in class loader's package entry table. |
2240 _package_entry = loader_data->packages()->lookup_only(pkg_name); |
2219 _package_entry = loader_data->packages()->lookup_only(pkg_name); |
2241 |
2220 |
2242 // If the package name is not found in the loader's package |
2221 // If the package name is not found in the loader's package |
2243 // entry table, it is an indication that the package has not |
2222 // entry table, it is an indication that the package has not |
2329 bool InstanceKlass::is_same_class_package(oop class_loader1, const Symbol* class_name1, |
2308 bool InstanceKlass::is_same_class_package(oop class_loader1, const Symbol* class_name1, |
2330 oop class_loader2, const Symbol* class_name2) { |
2309 oop class_loader2, const Symbol* class_name2) { |
2331 if (class_loader1 != class_loader2) { |
2310 if (class_loader1 != class_loader2) { |
2332 return false; |
2311 return false; |
2333 } else if (class_name1 == class_name2) { |
2312 } else if (class_name1 == class_name2) { |
2334 return true; // skip painful bytewise comparison |
2313 return true; |
2335 } else { |
2314 } else { |
2336 ResourceMark rm; |
2315 ResourceMark rm; |
2337 |
2316 |
2338 // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly |
2317 bool bad_class_name = false; |
2339 // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding. |
2318 const char* name1 = ClassLoader::package_from_name((const char*) class_name1->as_C_string(), &bad_class_name); |
2340 // Otherwise, we just compare jbyte values between the strings. |
2319 if (bad_class_name) { |
2341 int length1 = 0; |
2320 return false; |
2342 int length2 = 0; |
2321 } |
2343 const jbyte *name1 = package_from_name(class_name1, length1); |
2322 |
2344 const jbyte *name2 = package_from_name(class_name2, length2); |
2323 const char* name2 = ClassLoader::package_from_name((const char*) class_name2->as_C_string(), &bad_class_name); |
2345 |
2324 if (bad_class_name) { |
2346 if ((length1 < 0) || (length2 < 0)) { |
|
2347 // error occurred parsing package name. |
|
2348 return false; |
2325 return false; |
2349 } |
2326 } |
2350 |
2327 |
2351 if ((name1 == NULL) || (name2 == NULL)) { |
2328 if ((name1 == NULL) || (name2 == NULL)) { |
2352 // One of the two doesn't have a package. Only return true |
2329 // One of the two doesn't have a package. Only return true |
2353 // if the other one also doesn't have a package. |
2330 // if the other one also doesn't have a package. |
2354 return name1 == name2; |
2331 return name1 == name2; |
2355 } |
2332 } |
2356 |
2333 |
2357 // Check that package part is identical |
2334 // Check that package is identical |
2358 return UTF8::equal(name1, length1, name2, length2); |
2335 return (strcmp(name1, name2) == 0); |
2359 } |
2336 } |
2360 } |
2337 } |
2361 |
2338 |
2362 // Returns true iff super_method can be overridden by a method in targetclassname |
2339 // Returns true iff super_method can be overridden by a method in targetclassname |
2363 // See JSL 3rd edition 8.4.6.1 |
2340 // See JLS 3rd edition 8.4.6.1 |
2364 // Assumes name-signature match |
2341 // Assumes name-signature match |
2365 // "this" is InstanceKlass of super_method which must exist |
2342 // "this" is InstanceKlass of super_method which must exist |
2366 // note that the InstanceKlass of the method in the targetclassname has not always been created yet |
2343 // note that the InstanceKlass of the method in the targetclassname has not always been created yet |
2367 bool InstanceKlass::is_override(const methodHandle& super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) { |
2344 bool InstanceKlass::is_override(const methodHandle& super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) { |
2368 // Private methods can not be overridden |
2345 // Private methods can not be overridden |