--- a/src/hotspot/share/oops/klass.cpp Thu Sep 20 21:47:13 2018 +0200
+++ b/src/hotspot/share/oops/klass.cpp Thu Sep 20 22:01:12 2018 +0200
@@ -142,7 +142,10 @@
void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
- THROW(vmSymbols::java_lang_ArrayStoreException());
+ ResourceMark rm(THREAD);
+ assert(s != NULL, "Throw NPE!");
+ THROW_MSG(vmSymbols::java_lang_ArrayStoreException(),
+ err_msg("arraycopy: source type %s is not an array", s->klass()->external_name()));
}
@@ -165,7 +168,9 @@
return NULL;
}
-Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature, OverpassLookupMode overpass_mode) const {
+Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature,
+ OverpassLookupMode overpass_mode,
+ PrivateLookupMode private_mode) const {
#ifdef ASSERT
tty->print_cr("Error: uncached_lookup_method called on a klass oop."
" Likely error: reflection method does not correctly"
@@ -185,9 +190,10 @@
// which doesn't zero out the memory before calling the constructor.
// Need to set the _java_mirror field explicitly to not hit an assert that the field
// should be NULL before setting it.
-Klass::Klass() : _prototype_header(markOopDesc::prototype()),
- _shared_class_path_index(-1),
- _java_mirror(NULL) {
+Klass::Klass(KlassID id) : _id(id),
+ _java_mirror(NULL),
+ _prototype_header(markOopDesc::prototype()),
+ _shared_class_path_index(-1) {
CDS_ONLY(_shared_class_flags = 0;)
CDS_JAVA_HEAP_ONLY(_archived_mirror = 0;)
_primary_supers[0] = this;
@@ -223,7 +229,7 @@
return true;
}
-void Klass::initialize_supers(Klass* k, Array<Klass*>* transitive_interfaces, TRAPS) {
+void Klass::initialize_supers(Klass* k, Array<InstanceKlass*>* transitive_interfaces, TRAPS) {
if (FastSuperclassLimit == 0) {
// None of the other machinery matters.
set_super(k);
@@ -342,7 +348,7 @@
}
GrowableArray<Klass*>* Klass::compute_secondary_supers(int num_extra_slots,
- Array<Klass*>* transitive_interfaces) {
+ Array<InstanceKlass*>* transitive_interfaces) {
assert(num_extra_slots == 0, "override for complex klasses");
assert(transitive_interfaces == NULL, "sanity");
set_secondary_supers(Universe::the_empty_klass_array());
@@ -383,6 +389,10 @@
debug_only(verify();)
}
+oop Klass::holder_phantom() const {
+ return class_loader_data()->holder_phantom();
+}
+
void Klass::clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses) {
if (!ClassUnloading || !unloading_occurred) {
return;
@@ -529,20 +539,19 @@
Handle module_handle(THREAD, ((module_entry != NULL) ? module_entry->module() : (oop)NULL));
if (this->has_raw_archived_mirror()) {
+ ResourceMark rm;
log_debug(cds, mirror)("%s has raw archived mirror", external_name());
if (MetaspaceShared::open_archive_heap_region_mapped()) {
- oop m = archived_java_mirror();
- log_debug(cds, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
- if (m != NULL) {
- // mirror is archived, restore
- assert(MetaspaceShared::is_archive_object(m), "must be archived mirror object");
- Handle m_h(THREAD, m);
- java_lang_Class::restore_archived_mirror(this, m_h, loader, module_handle, protection_domain, CHECK);
+ bool present = java_lang_Class::restore_archived_mirror(this, loader, module_handle,
+ protection_domain,
+ CHECK);
+ if (present) {
return;
}
}
// No archived mirror data
+ log_debug(cds, mirror)("No archived mirror data for %s", external_name());
_java_mirror = NULL;
this->clear_has_raw_archived_mirror();
}
@@ -558,16 +567,13 @@
#if INCLUDE_CDS_JAVA_HEAP
// Used at CDS dump time to access the archived mirror. No GC barrier.
oop Klass::archived_java_mirror_raw() {
- assert(DumpSharedSpaces, "called only during runtime");
assert(has_raw_archived_mirror(), "must have raw archived mirror");
return CompressedOops::decode(_archived_mirror);
}
-// Used at CDS runtime to get the archived mirror from shared class. Uses GC barrier.
-oop Klass::archived_java_mirror() {
- assert(UseSharedSpaces, "UseSharedSpaces expected.");
+narrowOop Klass::archived_java_mirror_raw_narrow() {
assert(has_raw_archived_mirror(), "must have raw archived mirror");
- return RootAccess<IN_ARCHIVE_ROOT>::oop_load(&_archived_mirror);
+ return _archived_mirror;
}
// No GC barrier
@@ -611,7 +617,7 @@
const char* Klass::external_name() const {
if (is_instance_klass()) {
const InstanceKlass* ik = static_cast<const InstanceKlass*>(this);
- if (ik->is_anonymous()) {
+ if (ik->is_unsafe_anonymous()) {
char addr_buf[20];
jio_snprintf(addr_buf, 20, "/" INTPTR_FORMAT, p2i(ik));
size_t addr_len = strlen(addr_buf);
@@ -764,89 +770,126 @@
return true;
}
-bool Klass::verify_itable_index(int i) {
- assert(is_instance_klass(), "");
- int method_count = klassItable::method_count_for_interface(this);
- assert(i >= 0 && i < method_count, "index out of bounds");
- return true;
-}
-
#endif // PRODUCT
-// The caller of class_loader_and_module_name() (or one of its callers)
-// must use a ResourceMark in order to correctly free the result.
-const char* Klass::class_loader_and_module_name() const {
- const char* delim = "/";
- size_t delim_len = strlen(delim);
-
- const char* fqn = external_name();
- // Length of message to return; always include FQN
- size_t msglen = strlen(fqn) + 1;
-
- bool has_cl_name = false;
- bool has_mod_name = false;
- bool has_version = false;
+// Caller needs ResourceMark
+// joint_in_module_of_loader provides an optimization if 2 classes are in
+// the same module to succinctly print out relevant information about their
+// module name and class loader's name_and_id for error messages.
+// Format:
+// <fully-qualified-external-class-name1> and <fully-qualified-external-class-name2>
+// are in module <module-name>[@<version>]
+// of loader <loader-name_and_id>[, parent loader <parent-loader-name_and_id>]
+const char* Klass::joint_in_module_of_loader(const Klass* class2, bool include_parent_loader) const {
+ assert(module() == class2->module(), "classes do not have the same module");
+ const char* class1_name = external_name();
+ size_t len = strlen(class1_name) + 1;
- // Use class loader name, if exists and not builtin
- const char* class_loader_name = "";
- ClassLoaderData* cld = class_loader_data();
- assert(cld != NULL, "class_loader_data should not be NULL");
- if (!cld->is_builtin_class_loader_data()) {
- // If not builtin, look for name
- oop loader = class_loader();
- if (loader != NULL) {
- oop class_loader_name_oop = java_lang_ClassLoader::name(loader);
- if (class_loader_name_oop != NULL) {
- class_loader_name = java_lang_String::as_utf8_string(class_loader_name_oop);
- if (class_loader_name != NULL && class_loader_name[0] != '\0') {
- has_cl_name = true;
- msglen += strlen(class_loader_name) + delim_len;
- }
- }
- }
+ const char* class2_description = class2->class_in_module_of_loader(true, include_parent_loader);
+ len += strlen(class2_description);
+
+ len += strlen(" and ");
+
+ char* joint_description = NEW_RESOURCE_ARRAY_RETURN_NULL(char, len);
+
+ // Just return the FQN if error when allocating string
+ if (joint_description == NULL) {
+ return class1_name;
}
+ jio_snprintf(joint_description, len, "%s and %s",
+ class1_name,
+ class2_description);
+
+ return joint_description;
+}
+
+// Caller needs ResourceMark
+// class_in_module_of_loader provides a standard way to include
+// relevant information about a class, such as its module name as
+// well as its class loader's name_and_id, in error messages and logging.
+// Format:
+// <fully-qualified-external-class-name> is in module <module-name>[@<version>]
+// of loader <loader-name_and_id>[, parent loader <parent-loader-name_and_id>]
+const char* Klass::class_in_module_of_loader(bool use_are, bool include_parent_loader) const {
+ // 1. fully qualified external name of class
+ const char* klass_name = external_name();
+ size_t len = strlen(klass_name) + 1;
+
+ // 2. module name + @version
const char* module_name = "";
const char* version = "";
+ bool has_version = false;
+ bool module_is_named = false;
+ const char* module_name_phrase = "";
const Klass* bottom_klass = is_objArray_klass() ?
- ObjArrayKlass::cast(this)->bottom_klass() : this;
+ ObjArrayKlass::cast(this)->bottom_klass() : this;
if (bottom_klass->is_instance_klass()) {
ModuleEntry* module = InstanceKlass::cast(bottom_klass)->module();
- // Use module name, if exists
if (module->is_named()) {
- has_mod_name = true;
+ module_is_named = true;
+ module_name_phrase = "module ";
module_name = module->name()->as_C_string();
- msglen += strlen(module_name);
+ len += strlen(module_name);
// Use version if exists and is not a jdk module
- if (module->is_non_jdk_module() && module->version() != NULL) {
+ if (module->should_show_version()) {
has_version = true;
version = module->version()->as_C_string();
- msglen += strlen("@") + strlen(version);
+ // Include stlen(version) + 1 for the "@"
+ len += strlen(version) + 1;
}
+ } else {
+ module_name = UNNAMED_MODULE;
+ len += UNNAMED_MODULE_LEN;
}
} else {
- // klass is an array of primitives, so its module is java.base
+ // klass is an array of primitives, module is java.base
+ module_is_named = true;
+ module_name_phrase = "module ";
module_name = JAVA_BASE_NAME;
- }
-
- if (has_cl_name || has_mod_name) {
- msglen += delim_len;
+ len += JAVA_BASE_NAME_LEN;
}
- char* message = NEW_RESOURCE_ARRAY_RETURN_NULL(char, msglen);
+ // 3. class loader's name_and_id
+ ClassLoaderData* cld = class_loader_data();
+ assert(cld != NULL, "class_loader_data should not be null");
+ const char* loader_name_and_id = cld->loader_name_and_id();
+ len += strlen(loader_name_and_id);
- // Just return the FQN if error in allocating string
- if (message == NULL) {
- return fqn;
+ // 4. include parent loader information
+ const char* parent_loader_phrase = "";
+ const char* parent_loader_name_and_id = "";
+ if (include_parent_loader &&
+ !cld->is_builtin_class_loader_data()) {
+ oop parent_loader = java_lang_ClassLoader::parent(class_loader());
+ ClassLoaderData *parent_cld = ClassLoaderData::class_loader_data(parent_loader);
+ assert(parent_cld != NULL, "parent's class loader data should not be null");
+ parent_loader_name_and_id = parent_cld->loader_name_and_id();
+ parent_loader_phrase = ", parent loader ";
+ len += strlen(parent_loader_phrase) + strlen(parent_loader_name_and_id);
}
- jio_snprintf(message, msglen, "%s%s%s%s%s%s%s",
- class_loader_name,
- (has_cl_name) ? delim : "",
- (has_mod_name) ? module_name : "",
+ // Start to construct final full class description string
+ len += ((use_are) ? strlen(" are in ") : strlen(" is in "));
+ len += strlen(module_name_phrase) + strlen(" of loader ");
+
+ char* class_description = NEW_RESOURCE_ARRAY_RETURN_NULL(char, len);
+
+ // Just return the FQN if error when allocating string
+ if (class_description == NULL) {
+ return klass_name;
+ }
+
+ jio_snprintf(class_description, len, "%s %s in %s%s%s%s of loader %s%s%s",
+ klass_name,
+ (use_are) ? "are" : "is",
+ module_name_phrase,
+ module_name,
(has_version) ? "@" : "",
(has_version) ? version : "",
- (has_cl_name || has_mod_name) ? delim : "",
- fqn);
- return message;
+ loader_name_and_id,
+ parent_loader_phrase,
+ parent_loader_name_and_id);
+
+ return class_description;
}