8216308: StackTraceElement::fill_in can use injected Class source-file

Reviewed-by: coleenp, dholmes
This commit is contained in:
Aleksey Shipilev 2019-01-14 17:20:20 +01:00
parent 084f0b75bd
commit 88366150c6
3 changed files with 38 additions and 5 deletions

View File

@ -1354,6 +1354,16 @@ oop java_lang_Class::name(Handle java_class, TRAPS) {
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 @@ void java_lang_StackTraceElement::fill_in(Handle element,
} 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::_component_mirror_offset;
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;

View File

@ -219,7 +219,8 @@ class java_lang_String : AllStatic {
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 @@ class java_lang_Class : AllStatic {
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 @@ class java_lang_Class : AllStatic {
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);

View File

@ -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") \