Skip to content

Commit 6545e0d

Browse files
SendaoYanjianglizhouDavid Holmes
committed
8353189: [ASAN] memory leak after 8352184
Co-authored-by: Jiangli Zhou <jiangli@openjdk.org> Co-authored-by: David Holmes <dholmes@openjdk.org> Reviewed-by: dholmes, jiangli
1 parent f94a4f7 commit 6545e0d

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/hotspot/share/runtime/abstract_vm_version.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,42 +137,46 @@ const char* Abstract_VM_Version::vm_vendor() {
137137
}
138138

139139

140+
// The VM info string should be a constant, but its value cannot be finalized until after VM arguments
141+
// have been fully processed. And we want to avoid dynamic memory allocation which will cause ASAN
142+
// report error, so we enumerate all the cases by static const string value.
140143
const char* Abstract_VM_Version::vm_info_string() {
141-
const char* mode;
142144
switch (Arguments::mode()) {
143145
case Arguments::_int:
144-
mode = "interpreted mode";
145-
break;
146+
if (is_vm_statically_linked()) {
147+
return CDSConfig::is_using_archive() ? "interpreted mode, static, sharing" : "interpreted mode, static";
148+
} else {
149+
return CDSConfig::is_using_archive() ? "interpreted mode, sharing" : "interpreted mode";
150+
}
146151
case Arguments::_mixed:
147-
if (CompilationModeFlag::quick_only()) {
148-
mode = "mixed mode, emulated-client";
152+
if (is_vm_statically_linked()) {
153+
if (CompilationModeFlag::quick_only()) {
154+
return CDSConfig::is_using_archive() ? "mixed mode, emulated-client, static, sharing" : "mixed mode, emulated-client, static";
155+
} else {
156+
return CDSConfig::is_using_archive() ? "mixed mode, static, sharing" : "mixed mode, static";
157+
}
149158
} else {
150-
mode = "mixed mode";
159+
if (CompilationModeFlag::quick_only()) {
160+
return CDSConfig::is_using_archive() ? "mixed mode, emulated-client, sharing" : "mixed mode, emulated-client";
161+
} else {
162+
return CDSConfig::is_using_archive() ? "mixed mode, sharing" : "mixed mode";
163+
}
151164
}
152-
break;
153165
case Arguments::_comp:
154-
if (CompilationModeFlag::quick_only()) {
155-
mode = "compiled mode, emulated-client";
166+
if (is_vm_statically_linked()) {
167+
if (CompilationModeFlag::quick_only()) {
168+
return CDSConfig::is_using_archive() ? "compiled mode, emulated-client, static, sharing" : "compiled mode, emulated-client, static";
169+
}
170+
return CDSConfig::is_using_archive() ? "compiled mode, static, sharing" : "compiled mode, static";
156171
} else {
157-
mode = "compiled mode";
172+
if (CompilationModeFlag::quick_only()) {
173+
return CDSConfig::is_using_archive() ? "compiled mode, emulated-client, sharing" : "compiled mode, emulated-client";
174+
}
175+
return CDSConfig::is_using_archive() ? "compiled mode, sharing" : "compiled mode";
158176
}
159-
break;
160-
default:
161-
ShouldNotReachHere();
162177
}
163-
164-
const char* static_info = ", static";
165-
const char* sharing_info = ", sharing";
166-
size_t len = strlen(mode) +
167-
(is_vm_statically_linked() ? strlen(static_info) : 0) +
168-
(CDSConfig::is_using_archive() ? strlen(sharing_info) : 0) +
169-
1;
170-
char* vm_info = NEW_C_HEAP_ARRAY(char, len, mtInternal);
171-
// jio_snprintf places null character in the last character.
172-
jio_snprintf(vm_info, len, "%s%s%s", mode,
173-
is_vm_statically_linked() ? static_info : "",
174-
CDSConfig::is_using_archive() ? sharing_info : "");
175-
return vm_info;
178+
ShouldNotReachHere();
179+
return "";
176180
}
177181

178182
// NOTE: do *not* use stringStream. this function is called by

0 commit comments

Comments
 (0)