8216308: StackTraceElement::fill_in can use injected Class source-file
Reviewed-by: coleenp, dholmes
--- a/src/hotspot/share/classfile/javaClasses.cpp Mon Jan 14 00:00:00 2019 +0100
+++ b/src/hotspot/share/classfile/javaClasses.cpp Mon Jan 14 17:20:20 2019 +0100
@@ -1354,6 +1354,16 @@
return o;
}
+oop java_lang_Class::source_file(oop java_class) {
+ assert(_source_file_offset != 0, "must be set");
+ return java_class->obj_field(_source_file_offset);
+}
+
+void java_lang_Class::set_source_file(oop java_class, oop source_file) {
+ assert(_source_file_offset != 0, "must be set");
+ java_class->obj_field_put(_source_file_offset, source_file);
+}
+
oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS) {
// This should be improved by adding a field at the Java level or by
// introducing a new VM klass (see comment in ClassFileParser)
@@ -2602,10 +2612,26 @@
} else {
// Fill in source file name and line number.
Symbol* source = Backtrace::get_source_file_name(holder, version);
- if (ShowHiddenFrames && source == NULL)
- source = vmSymbols::unknown_class_name();
- oop filename = StringTable::intern(source, CHECK);
- java_lang_StackTraceElement::set_fileName(element(), filename);
+ oop source_file = java_lang_Class::source_file(java_class());
+ if (source != NULL) {
+ // Class was not redefined. We can trust its cache if set,
+ // else we have to initialize it.
+ if (source_file == NULL) {
+ source_file = StringTable::intern(source, CHECK);
+ java_lang_Class::set_source_file(java_class(), source_file);
+ }
+ } else {
+ // Class was redefined. Dump the cache if it was set.
+ if (source_file != NULL) {
+ source_file = NULL;
+ java_lang_Class::set_source_file(java_class(), source_file);
+ }
+ if (ShowHiddenFrames) {
+ source = vmSymbols::unknown_class_name();
+ source_file = StringTable::intern(source, CHECK);
+ }
+ }
+ java_lang_StackTraceElement::set_fileName(element(), source_file);
int line_number = Backtrace::get_line_number(method, bci);
java_lang_StackTraceElement::set_lineNumber(element(), line_number);
@@ -3980,6 +4006,7 @@
int java_lang_Class::_init_lock_offset;
int java_lang_Class::_signers_offset;
int java_lang_Class::_name_offset;
+int java_lang_Class::_source_file_offset;
GrowableArray<Klass*>* java_lang_Class::_fixup_mirror_list = NULL;
GrowableArray<Klass*>* java_lang_Class::_fixup_module_field_list = NULL;
int java_lang_Throwable::backtrace_offset;
--- a/src/hotspot/share/classfile/javaClasses.hpp Mon Jan 14 00:00:00 2019 +0100
+++ b/src/hotspot/share/classfile/javaClasses.hpp Mon Jan 14 17:20:20 2019 +0100
@@ -219,7 +219,8 @@
macro(java_lang_Class, oop_size, int_signature, false) \
macro(java_lang_Class, static_oop_field_count, int_signature, false) \
macro(java_lang_Class, protection_domain, object_signature, false) \
- macro(java_lang_Class, signers, object_signature, false)
+ macro(java_lang_Class, signers, object_signature, false) \
+ macro(java_lang_Class, source_file, object_signature, false) \
class java_lang_Class : AllStatic {
friend class VMStructs;
@@ -241,6 +242,7 @@
static int _module_offset;
static int _component_mirror_offset;
static int _name_offset;
+ static int _source_file_offset;
static bool offsets_computed;
static int classRedefinedCount_offset;
@@ -313,6 +315,9 @@
static oop name(Handle java_class, TRAPS);
+ static oop source_file(oop java_class);
+ static void set_source_file(oop java_class, oop source_file);
+
static int oop_size(oop java_class);
static int oop_size_raw(oop java_class);
static void set_oop_size(HeapWord* java_class, int size);
--- a/src/hotspot/share/classfile/vmSymbols.hpp Mon Jan 14 00:00:00 2019 +0100
+++ b/src/hotspot/share/classfile/vmSymbols.hpp Mon Jan 14 17:20:20 2019 +0100
@@ -425,6 +425,7 @@
template(static_oop_field_count_name, "static_oop_field_count") \
template(protection_domain_name, "protection_domain") \
template(signers_name, "signers_name") \
+ template(source_file_name, "source_file") \
template(loader_data_name, "loader_data") \
template(vmdependencies_name, "vmdependencies") \
template(last_cleanup_name, "last_cleanup") \