Revert "Revert "Cleanup jvmti tests""

This reverts commit 2a9d198b9929560c9ab07691b3afbe275483be95.

Test: mma -j40 test-art-host
Test: ART_TEST_RUN_TEST_NDEBUG=true mma -j40 test-art-host

Change-Id: I14bfd02f74f93e4a6b853287fcaa69f1fb027256
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 566f7ba..8245947 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -30,6 +30,7 @@
 INTERPRETER="n"
 JIT="n"
 INVOKE_WITH=""
+IS_JVMTI_TEST="n"
 ISA=x86
 LIBRARY_DIRECTORY="lib"
 TEST_DIRECTORY="nativetest"
@@ -59,14 +60,18 @@
 EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
 DRY_RUN="n" # if y prepare to run the test but don't run it.
 TEST_VDEX="n"
+TEST_IS_NDEBUG="n"
 APP_IMAGE="y"
 
 while true; do
     if [ "x$1" = "x--quiet" ]; then
         QUIET="y"
         shift
+    elif [ "x$1" = "x--jvmti" ]; then
+        IS_JVMTI_TEST="y"
+        shift
     elif [ "x$1" = "x-O" ]; then
-        # Ignore this option.
+        TEST_IS_NDEBUG="y"
         shift
     elif [ "x$1" = "x--lib" ]; then
         shift
@@ -382,6 +387,28 @@
     fi
 fi
 
+if [ "$IS_JVMTI_TEST" = "y" ]; then
+  plugin=libopenjdkjvmtid.so
+  agent=libtiagentd.so
+  lib=tiagentd
+  if  [[ "$TEST_IS_NDEBUG" = "y" ]]; then
+    agent=libtiagent.so
+    plugin=libopenjdkjvmti.so
+    lib=tiagent
+  fi
+
+  ARGS="${ARGS} ${lib}"
+  if [[ "$USE_JVM" = "y" ]]; then
+    FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},jvm"
+  else
+    FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
+    FLAGS="${FLAGS} -Xplugin:${plugin}"
+    FLAGS="${FLAGS} -Xfully-deoptable"
+    # Always make the compilation be debuggable.
+    COMPILE_FLAGS="${COMPILE_FLAGS} --debuggable"
+  fi
+fi
+
 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
 
 if [ "$RELOCATE" = "y" ]; then