Skip to content

Commit 96805ae

Browse files
author
SendaoYan
committed
8224624: Inefficiencies in CodeStrings::add_comment cause timeouts
Changing CodeStrings to a doubly-linked-list and searching for the comment with the right offset in reverse. Backport-of: 7cff981
1 parent 98161b7 commit 96805ae

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/hotspot/share/asm/codeBuffer.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,26 +1046,32 @@ class CodeString: public CHeapObj<mtCode> {
10461046
friend class CodeStrings;
10471047
const char * _string;
10481048
CodeString* _next;
1049+
CodeString* _prev;
10491050
intptr_t _offset;
10501051

10511052
~CodeString() {
1052-
assert(_next == NULL, "wrong interface for freeing list");
1053+
assert(_next == NULL && _prev == NULL, "wrong interface for freeing list");
10531054
os::free((void*)_string);
10541055
}
10551056

10561057
bool is_comment() const { return _offset >= 0; }
10571058

10581059
public:
10591060
CodeString(const char * string, intptr_t offset = -1)
1060-
: _next(NULL), _offset(offset) {
1061+
: _next(NULL), _prev(NULL), _offset(offset) {
10611062
_string = os::strdup(string, mtCode);
10621063
}
10631064

10641065
const char * string() const { return _string; }
10651066
intptr_t offset() const { assert(_offset >= 0, "offset for non comment?"); return _offset; }
10661067
CodeString* next() const { return _next; }
10671068

1068-
void set_next(CodeString* next) { _next = next; }
1069+
void set_next(CodeString* next) {
1070+
_next = next;
1071+
if (next != NULL) {
1072+
next->_prev = this;
1073+
}
1074+
}
10691075

10701076
CodeString* first_comment() {
10711077
if (is_comment()) {
@@ -1093,12 +1099,9 @@ CodeString* CodeStrings::find(intptr_t offset) const {
10931099

10941100
// Convenience for add_comment.
10951101
CodeString* CodeStrings::find_last(intptr_t offset) const {
1096-
CodeString* a = find(offset);
1097-
if (a != NULL) {
1098-
CodeString* c = NULL;
1099-
while (((c = a->next_comment()) != NULL) && (c->offset() == offset)) {
1100-
a = c;
1101-
}
1102+
CodeString* a = _strings_last;
1103+
while (a != NULL && !a->is_comment() && a->offset() > offset) {
1104+
a = a->_prev;
11021105
}
11031106
return a;
11041107
}
@@ -1117,12 +1120,16 @@ void CodeStrings::add_comment(intptr_t offset, const char * comment) {
11171120
c->set_next(_strings);
11181121
_strings = c;
11191122
}
1123+
if (c->next() == NULL) {
1124+
_strings_last = c;
1125+
}
11201126
}
11211127

11221128
void CodeStrings::assign(CodeStrings& other) {
11231129
other.check_valid();
11241130
assert(is_null(), "Cannot assign onto non-empty CodeStrings");
11251131
_strings = other._strings;
1132+
_strings_last = other._strings_last;
11261133
#ifdef ASSERT
11271134
_defunct = false;
11281135
#endif
@@ -1138,8 +1145,11 @@ void CodeStrings::copy(CodeStrings& other) {
11381145
assert(is_null(), "Cannot copy onto non-empty CodeStrings");
11391146
CodeString* n = other._strings;
11401147
CodeString** ps = &_strings;
1148+
CodeString* prev = NULL;
11411149
while (n != NULL) {
11421150
*ps = new CodeString(n->string(),n->offset());
1151+
(*ps)->_prev = prev;
1152+
prev = *ps;
11431153
ps = &((*ps)->_next);
11441154
n = n->next();
11451155
}
@@ -1168,6 +1178,10 @@ void CodeStrings::free() {
11681178
// unlink the node from the list saving a pointer to the next
11691179
CodeString* p = n->next();
11701180
n->set_next(NULL);
1181+
if (p != NULL) {
1182+
assert(p->_prev == n, "missing prev link");
1183+
p->_prev = NULL;
1184+
}
11711185
delete n;
11721186
n = p;
11731187
}
@@ -1178,6 +1192,9 @@ const char* CodeStrings::add_string(const char * string) {
11781192
check_valid();
11791193
CodeString* s = new CodeString(string);
11801194
s->set_next(_strings);
1195+
if (_strings == NULL) {
1196+
_strings_last = s;
1197+
}
11811198
_strings = s;
11821199
assert(s->string() != NULL, "should have a string");
11831200
return s->string();

src/hotspot/share/asm/codeBuffer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ class CodeStrings {
249249
private:
250250
#ifndef PRODUCT
251251
CodeString* _strings;
252+
CodeString* _strings_last;
252253
#ifdef ASSERT
253254
// Becomes true after copy-out, forbids further use.
254255
bool _defunct; // Zero bit pattern is "valid", see memset call in decode_env::decode_env
@@ -262,6 +263,7 @@ class CodeStrings {
262263
void set_null_and_invalidate() {
263264
#ifndef PRODUCT
264265
_strings = NULL;
266+
_strings_last = NULL;
265267
#ifdef ASSERT
266268
_defunct = true;
267269
#endif
@@ -272,6 +274,7 @@ class CodeStrings {
272274
CodeStrings() {
273275
#ifndef PRODUCT
274276
_strings = NULL;
277+
_strings_last = NULL;
275278
#ifdef ASSERT
276279
_defunct = false;
277280
#endif

0 commit comments

Comments
 (0)