ART: Fix GetErrorName.
Add missing case for JVMTI_ERROR_THREAD_SUSPENDED. Also return
JVMTI_ERROR_ILLEGAL_ARGUMENT for unspecified inputs.
Refactor the code
* Remove the switch default case for case checking
* Use a lambda to unify the return code. This saves 4K of so size.
Add a test.
Bug: 38133825
Test: m
Test: art/test/testrunner/testrunner.py -b --host -t 901
Change-Id: If46b276b8abcd8b7b8ebbac1106f6b840761b997
diff --git a/runtime/openjdkjvmti/OpenjdkJvmTi.cc b/runtime/openjdkjvmti/OpenjdkJvmTi.cc
index 4c00317..0921cea 100644
--- a/runtime/openjdkjvmti/OpenjdkJvmTi.cc
+++ b/runtime/openjdkjvmti/OpenjdkJvmTi.cc
@@ -1505,23 +1505,26 @@
static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) {
ENSURE_NON_NULL(name_ptr);
+ auto copy_fn = [&](const char* name_cstr) {
+ jvmtiError res;
+ JvmtiUniquePtr<char[]> copy = CopyString(env, name_cstr, &res);
+ if (copy == nullptr) {
+ *name_ptr = nullptr;
+ return res;
+ } else {
+ *name_ptr = copy.release();
+ return OK;
+ }
+ };
switch (error) {
-#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : do { \
- jvmtiError res; \
- JvmtiUniquePtr<char[]> copy = CopyString(env, "JVMTI_ERROR_"#e, &res); \
- if (copy == nullptr) { \
- *name_ptr = nullptr; \
- return res; \
- } else { \
- *name_ptr = copy.release(); \
- return OK; \
- } \
- } while (false)
+#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : \
+ return copy_fn("JVMTI_ERROR_"#e);
ERROR_CASE(NONE);
ERROR_CASE(INVALID_THREAD);
ERROR_CASE(INVALID_THREAD_GROUP);
ERROR_CASE(INVALID_PRIORITY);
ERROR_CASE(THREAD_NOT_SUSPENDED);
+ ERROR_CASE(THREAD_SUSPENDED);
ERROR_CASE(THREAD_NOT_ALIVE);
ERROR_CASE(INVALID_OBJECT);
ERROR_CASE(INVALID_CLASS);
@@ -1566,18 +1569,9 @@
ERROR_CASE(UNATTACHED_THREAD);
ERROR_CASE(INVALID_ENVIRONMENT);
#undef ERROR_CASE
- default: {
- jvmtiError res;
- JvmtiUniquePtr<char[]> copy = CopyString(env, "JVMTI_ERROR_UNKNOWN", &res);
- if (copy == nullptr) {
- *name_ptr = nullptr;
- return res;
- } else {
- *name_ptr = copy.release();
- return ERR(ILLEGAL_ARGUMENT);
- }
- }
}
+
+ return ERR(ILLEGAL_ARGUMENT);
}
static jvmtiError SetVerboseFlag(jvmtiEnv* env,