|
26 | 26 | #include "utilities/macros.hpp"
|
27 | 27 | #if INCLUDE_MANAGEMENT
|
28 | 28 | #include "classfile/classLoaderDataGraph.inline.hpp"
|
| 29 | +#include "classfile/javaClasses.inline.hpp" |
| 30 | +#include "classfile/symbolTable.hpp" |
29 | 31 | #include "memory/resourceArea.hpp"
|
30 | 32 | #include "logging/log.hpp"
|
| 33 | +#include "oops/instanceKlass.inline.hpp" |
31 | 34 | #include "runtime/atomic.hpp"
|
| 35 | +#include "runtime/fieldDescriptor.inline.hpp" |
32 | 36 | #include "runtime/interfaceSupport.inline.hpp"
|
33 | 37 | #include "runtime/mutexLocker.hpp"
|
34 | 38 | #include "runtime/synchronizer.hpp"
|
|
37 | 41 | #include "utilities/concurrentHashTableTasks.inline.hpp"
|
38 | 42 | #include "utilities/debug.hpp"
|
39 | 43 |
|
| 44 | +static const char* allocate(oop string) { |
| 45 | + char* str = nullptr; |
| 46 | + const typeArrayOop value = java_lang_String::value(string); |
| 47 | + if (value != nullptr) { |
| 48 | + const int length = java_lang_String::utf8_length(string, value); |
| 49 | + str = NEW_C_HEAP_ARRAY(char, length, mtServiceability); |
| 50 | + java_lang_String::as_utf8_string(string, value, str, length + 1); |
| 51 | + } |
| 52 | + return str; |
| 53 | +} |
| 54 | + |
| 55 | +static int compute_field_offset(const Klass* klass, const char* field_name, const char* field_signature) { |
| 56 | + assert(klass != nullptr, "invariant"); |
| 57 | + Symbol* const name = SymbolTable::new_symbol(field_name); |
| 58 | + assert(name != nullptr, "invariant"); |
| 59 | + Symbol* const signature = SymbolTable::new_symbol(field_signature); |
| 60 | + assert(signature != nullptr, "invariant"); |
| 61 | + assert(klass->is_instance_klass(), "invariant"); |
| 62 | + fieldDescriptor fd; |
| 63 | + InstanceKlass::cast(klass)->find_field(name, signature, false, &fd); |
| 64 | + return fd.offset(); |
| 65 | +} |
| 66 | + |
| 67 | +static const char* location_no_frag_string(oop codesource) { |
| 68 | + assert(codesource != nullptr, "invariant"); |
| 69 | + static int loc_no_frag_offset = compute_field_offset(codesource->klass(), "locationNoFragString", "Ljava/lang/String;"); |
| 70 | + oop string = codesource->obj_field(loc_no_frag_offset); |
| 71 | + return string != nullptr ? allocate(string) : nullptr; |
| 72 | +} |
| 73 | + |
| 74 | +static oop codesource(oop pd) { |
| 75 | + assert(pd != nullptr, "invariant"); |
| 76 | + static int codesource_offset = compute_field_offset(pd->klass(), "codesource", "Ljava/security/CodeSource;"); |
| 77 | + return pd->obj_field(codesource_offset); |
| 78 | +} |
| 79 | + |
| 80 | +static const char* get_codesource(const InstanceKlass* ik) { |
| 81 | + assert(ik != nullptr, "invariant"); |
| 82 | + oop pd = java_lang_Class::protection_domain(ik->java_mirror()); |
| 83 | + if (pd == nullptr) { |
| 84 | + return nullptr; |
| 85 | + } |
| 86 | + oop cs = codesource(pd); |
| 87 | + return cs != nullptr ? location_no_frag_string(cs) : nullptr; |
| 88 | +} |
| 89 | + |
40 | 90 | FinalizerEntry::FinalizerEntry(const InstanceKlass* ik) :
|
41 | 91 | _ik(ik),
|
| 92 | + _codesource(get_codesource(ik)), |
42 | 93 | _objects_on_heap(0),
|
43 | 94 | _total_finalizers_run(0) {}
|
44 | 95 |
|
| 96 | +FinalizerEntry::~FinalizerEntry() { |
| 97 | + if (_codesource != nullptr) { |
| 98 | + FREE_C_HEAP_ARRAY(char, _codesource); |
| 99 | + } |
| 100 | +} |
| 101 | + |
45 | 102 | const InstanceKlass* FinalizerEntry::klass() const {
|
46 | 103 | return _ik;
|
47 | 104 | }
|
48 | 105 |
|
| 106 | +const char* FinalizerEntry::codesource() const { |
| 107 | + return _codesource; |
| 108 | +} |
| 109 | + |
49 | 110 | uintptr_t FinalizerEntry::objects_on_heap() const {
|
50 | 111 | return Atomic::load(&_objects_on_heap);
|
51 | 112 | }
|
|
0 commit comments