From e14af3c88675bb7bcfadacc4d8a334d296e22273 Mon Sep 17 00:00:00 2001 From: vkempik Date: Mon, 20 Jul 2015 18:57:07 +0300 Subject: [PATCH] 8048353: jstack -l crashes VM when a Java mirror for a primitive type is locked Reviewed-by: coleenp, dcubed --- src/share/vm/classfile/javaClasses.cpp | 16 ++++++++++++++++ src/share/vm/classfile/javaClasses.hpp | 1 + src/share/vm/runtime/vframe.cpp | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp index 3ffca687e..c245cc58f 100644 --- a/src/share/vm/classfile/javaClasses.cpp +++ b/src/share/vm/classfile/javaClasses.cpp @@ -782,6 +782,22 @@ Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found, return name; } +// Returns the Java name for this Java mirror (Resource allocated) +// See Klass::external_name(). +// For primitive type Java mirrors, its type name is returned. +const char* java_lang_Class::as_external_name(oop java_class) { + assert(java_lang_Class::is_instance(java_class), "must be a Class object"); + const char* name = NULL; + if (is_primitive(java_class)) { + name = type2name(primitive_type(java_class)); + } else { + name = as_Klass(java_class)->external_name(); + } + if (name == NULL) { + name = ""; + } + return name; +} Klass* java_lang_Class::array_klass(oop java_class) { Klass* k = ((Klass*)java_class->metadata_field(_array_klass_offset)); diff --git a/src/share/vm/classfile/javaClasses.hpp b/src/share/vm/classfile/javaClasses.hpp index 9a8b248ff..5e497e6aa 100644 --- a/src/share/vm/classfile/javaClasses.hpp +++ b/src/share/vm/classfile/javaClasses.hpp @@ -270,6 +270,7 @@ class java_lang_Class : AllStatic { } static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS); static void print_signature(oop java_class, outputStream *st); + static const char* as_external_name(oop java_class); // Testing static bool is_instance(oop obj) { return obj != NULL && obj->klass() == SystemDictionary::Class_klass(); diff --git a/src/share/vm/runtime/vframe.cpp b/src/share/vm/runtime/vframe.cpp index 5a3951e7a..0d5524118 100644 --- a/src/share/vm/runtime/vframe.cpp +++ b/src/share/vm/runtime/vframe.cpp @@ -148,8 +148,7 @@ static void print_locked_object_class_name(outputStream* st, Handle obj, const c if (obj.not_null()) { st->print("\t- %s <" INTPTR_FORMAT "> ", lock_state, (address)obj()); if (obj->klass() == SystemDictionary::Class_klass()) { - Klass* target_klass = java_lang_Class::as_Klass(obj()); - st->print_cr("(a java.lang.Class for %s)", InstanceKlass::cast(target_klass)->external_name()); + st->print_cr("(a java.lang.Class for %s)", java_lang_Class::as_external_name(obj())); } else { Klass* k = obj->klass(); st->print_cr("(a %s)", k->external_name()); -- GitLab