Skip to content

Commit 1b2147a

Browse files
author
Markus Grönlund
committed
8269125: Klass enqueue element size calculation wrong when traceid value cross compress limit
Reviewed-by: jbachorik, egahlin
1 parent bf70620 commit 1b2147a

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdKlassQueue.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static const size_t ELEMENT_SIZE = sizeof(JfrEpochQueueKlassElement);
6767
static const size_t NARROW_ELEMENT_SIZE = sizeof(JfrEpochQueueNarrowKlassElement);
6868
static const size_t THRESHOLD_SHIFT = 30;
6969

70-
// If the upshifted traceid value is less than this threshold (1 073 741 824),
70+
// If the traceid value is less than this threshold (1 073 741 824),
7171
// compress the element for more effective queue storage.
7272
static const traceid uncompressed_threshold = ((traceid)1) << THRESHOLD_SHIFT;
7373

@@ -121,30 +121,36 @@ static traceid read_element(const u1* pos, const Klass** klass, bool compressed)
121121
return compressed ? read_compressed_element(pos, klass) : read_uncompressed_element(pos, klass);
122122
}
123123

124+
template <typename T>
125+
static inline void store_traceid(T* element, traceid id, bool uncompressed) {
126+
#ifdef VM_LITTLE_ENDIAN
127+
id <<= METADATA_SHIFT;
128+
#endif
129+
element->id = uncompressed ? id | UNCOMPRESSED : id;
130+
}
131+
124132
static void store_compressed_element(traceid id, const Klass* klass, u1* pos) {
133+
assert(can_compress_element(id), "invariant");
125134
JfrEpochQueueNarrowKlassElement* const element = new (pos) JfrEpochQueueNarrowKlassElement();
126-
element->id = id;
135+
store_traceid(element, id, false);
127136
element->compressed_klass = encode(klass);
128137
}
129138

130139
static void store_uncompressed_element(traceid id, const Klass* klass, u1* pos) {
131140
JfrEpochQueueKlassElement* const element = new (pos) JfrEpochQueueKlassElement();
132-
element->id = id | UNCOMPRESSED;
141+
store_traceid(element, id, true);
133142
element->klass = klass;
134143
}
135144

136145
static void store_element(const Klass* klass, u1* pos) {
137146
assert(pos != NULL, "invariant");
138147
assert(klass != NULL, "invariant");
139-
traceid id = JfrTraceId::load_raw(klass);
140-
#ifdef VM_LITTLE_ENDIAN
141-
id <<= METADATA_SHIFT;
142-
#endif
148+
const traceid id = JfrTraceId::load_raw(klass);
143149
if (can_compress_element(id)) {
144150
store_compressed_element(id, klass, pos);
145-
} else {
146-
store_uncompressed_element(id, klass, pos);
151+
return;
147152
}
153+
store_uncompressed_element(id, klass, pos);
148154
}
149155

150156
static void set_unloaded(const u1* pos) {

src/hotspot/share/jfr/utilities/jfrEpochQueue.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ JfrEpochQueue<ElementPolicy>::storage_for_element(JfrEpochQueue<ElementPolicy>::
6868
template <template <typename> class ElementPolicy>
6969
void JfrEpochQueue<ElementPolicy>::enqueue(JfrEpochQueue<ElementPolicy>::TypePtr t) {
7070
assert(t != NULL, "invariant");
71-
static size_t element_size = _policy.element_size(t);
71+
size_t element_size = _policy.element_size(t);
7272
BufferPtr buffer = storage_for_element(t, element_size);
7373
assert(buffer != NULL, "invariant");
7474
_policy.store_element(t, buffer);

0 commit comments

Comments
 (0)