1
1
/*
2
- * Copyright (c) 2014, 2019 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2014, 2020 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
30
30
#include " jfr/leakprofiler/utilities/unifiedOop.hpp"
31
31
#include " oops/fieldStreams.hpp"
32
32
#include " oops/instanceKlass.hpp"
33
+ #include " oops/instanceMirrorKlass.hpp"
33
34
#include " oops/objArrayOop.inline.hpp"
34
35
#include " oops/oopsHierarchy.hpp"
35
36
#include " runtime/handles.inline.hpp"
@@ -38,60 +39,54 @@ bool EdgeUtils::is_leak_edge(const Edge& edge) {
38
39
return (const Edge*)edge.pointee ()->mark () == &edge;
39
40
}
40
41
41
- static int field_offset (const StoredEdge& edge) {
42
- assert (!edge.is_root (), " invariant" );
43
- const oop ref_owner = edge.reference_owner ();
42
+ static bool is_static_field (const oop ref_owner, const InstanceKlass* ik, int offset) {
43
+ assert (ref_owner != NULL , " invariant" );
44
+ assert (ik != NULL , " invariant" );
45
+ assert (ref_owner->klass () == ik, " invariant" );
46
+ return ik->is_mirror_instance_klass () && offset >= InstanceMirrorKlass::cast (ik)->offset_of_static_fields ();
47
+ }
48
+
49
+ static int field_offset (const Edge& edge, const oop ref_owner) {
44
50
assert (ref_owner != NULL , " invariant" );
51
+ assert (!ref_owner->is_array (), " invariant" );
52
+ assert (ref_owner->is_instance (), " invariant" );
45
53
const oop* reference = UnifiedOop::decode (edge.reference ());
46
54
assert (reference != NULL , " invariant" );
47
55
assert (!UnifiedOop::is_narrow (reference), " invariant" );
48
- assert (!ref_owner->is_array (), " invariant" );
49
- assert (ref_owner->is_instance (), " invariant" );
50
56
const int offset = (int )pointer_delta (reference, ref_owner, sizeof (char ));
51
- assert (offset < ( ref_owner->size () * HeapWordSize) , " invariant" );
57
+ assert (offset < ref_owner->size () * HeapWordSize, " invariant" );
52
58
return offset;
53
59
}
54
60
55
- static const InstanceKlass* field_type (const StoredEdge& edge) {
56
- assert (!edge.is_root () || !EdgeUtils::is_array_element (edge), " invariant" );
57
- return (const InstanceKlass*)edge.reference_owner_klass ();
58
- }
59
-
60
- const Symbol* EdgeUtils::field_name_symbol (const Edge& edge) {
61
+ const Symbol* EdgeUtils::field_name (const Edge& edge, jshort* modifiers) {
61
62
assert (!edge.is_root (), " invariant" );
62
- assert (!is_array_element (edge), " invariant" );
63
- const int offset = field_offset (edge);
64
- const InstanceKlass* ik = field_type (edge);
63
+ assert (!EdgeUtils::is_array_element (edge), " invariant" );
64
+ assert (modifiers != NULL , " invariant" );
65
+ const oop ref_owner = edge.reference_owner ();
66
+ assert (ref_owner != NULL , " invariant" );
67
+ assert (ref_owner->klass ()->is_instance_klass (), " invariant" );
68
+ const InstanceKlass* ik = InstanceKlass::cast (ref_owner->klass ());
69
+ const int offset = field_offset (edge, ref_owner);
70
+ if (is_static_field (ref_owner, ik, offset)) {
71
+ assert (ik->is_mirror_instance_klass (), " invariant" );
72
+ assert (java_lang_Class::as_Klass (ref_owner)->is_instance_klass (), " invariant" );
73
+ ik = InstanceKlass::cast (java_lang_Class::as_Klass (ref_owner));
74
+ }
65
75
while (ik != NULL ) {
66
76
JavaFieldStream jfs (ik);
67
77
while (!jfs.done ()) {
68
78
if (offset == jfs.offset ()) {
79
+ *modifiers = jfs.access_flags ().as_short ();
69
80
return jfs.name ();
70
81
}
71
82
jfs.next ();
72
83
}
73
- ik = (InstanceKlass*)ik->super ();
84
+ ik = (const InstanceKlass*)ik->super ();
74
85
}
86
+ *modifiers = 0 ;
75
87
return NULL ;
76
88
}
77
89
78
- jshort EdgeUtils::field_modifiers (const Edge& edge) {
79
- const int offset = field_offset (edge);
80
- const InstanceKlass* ik = field_type (edge);
81
-
82
- while (ik != NULL ) {
83
- JavaFieldStream jfs (ik);
84
- while (!jfs.done ()) {
85
- if (offset == jfs.offset ()) {
86
- return jfs.access_flags ().as_short ();
87
- }
88
- jfs.next ();
89
- }
90
- ik = (InstanceKlass*)ik->super ();
91
- }
92
- return 0 ;
93
- }
94
-
95
90
bool EdgeUtils::is_array_element (const Edge& edge) {
96
91
assert (!edge.is_root (), " invariant" );
97
92
const oop ref_owner = edge.reference_owner ();
@@ -100,7 +95,7 @@ bool EdgeUtils::is_array_element(const Edge& edge) {
100
95
}
101
96
102
97
static int array_offset (const Edge& edge) {
103
- assert (!edge. is_root ( ), " invariant" );
98
+ assert (EdgeUtils::is_array_element (edge ), " invariant" );
104
99
const oop ref_owner = edge.reference_owner ();
105
100
assert (ref_owner != NULL , " invariant" );
106
101
const oop* reference = UnifiedOop::decode (edge.reference ());
@@ -114,17 +109,15 @@ static int array_offset(const Edge& edge) {
114
109
}
115
110
116
111
int EdgeUtils::array_index (const Edge& edge) {
117
- return is_array_element (edge) ? array_offset (edge) : 0 ;
112
+ return array_offset (edge);
118
113
}
119
114
120
115
int EdgeUtils::array_size (const Edge& edge) {
121
- if (is_array_element (edge)) {
122
- const oop ref_owner = edge.reference_owner ();
123
- assert (ref_owner != NULL , " invariant" );
124
- assert (ref_owner->is_objArray (), " invariant" );
125
- return ((objArrayOop)(ref_owner))->length ();
126
- }
127
- return 0 ;
116
+ assert (is_array_element (edge), " invariant" );
117
+ const oop ref_owner = edge.reference_owner ();
118
+ assert (ref_owner != NULL , " invariant" );
119
+ assert (ref_owner->is_objArray (), " invariant" );
120
+ return ((objArrayOop)ref_owner)->length ();
128
121
}
129
122
130
123
const Edge* EdgeUtils::root (const Edge& edge) {
0 commit comments