akashche 02bc7e2
# HG changeset patch
akashche 02bc7e2
# User dsamersoff
akashche 02bc7e2
# Date 1409228402 25200
akashche 02bc7e2
#      Thu Aug 28 05:20:02 2014 -0700
akashche 02bc7e2
# Node ID f4c9545cd8a56a5fab74c95de3573623ba2b83c4
akashche 02bc7e2
# Parent  13411144d46b50d0087f35eca2b8e827aae558f1
akashche 02bc7e2
8049226, PR2960: com/sun/jdi/OptionTest.java test times out again
akashche 02bc7e2
Summary: Don't call jni_FatalError if transport initialization fails
akashche 02bc7e2
Reviewed-by: sspitsyn, sla
akashche 02bc7e2
akashche 02bc7e2
diff -r 13411144d46b -r f4c9545cd8a5 src/share/back/debugInit.c
akashche 02bc7e2
--- openjdk/jdk/src/share/back/debugInit.c	Wed Jun 18 03:29:58 2014 -0700
akashche 02bc7e2
+++ openjdk/jdk/src/share/back/debugInit.c	Thu Aug 28 05:20:02 2014 -0700
akashche 02bc7e2
@@ -1013,7 +1013,7 @@
akashche 02bc7e2
 atexit_finish_logging(void)
akashche 02bc7e2
 {
akashche 02bc7e2
     /* Normal exit(0) (not _exit()) may only reach here */
akashche 02bc7e2
-    finish_logging(0);  /* Only first call matters */
akashche 02bc7e2
+    finish_logging();  /* Only first call matters */
akashche 02bc7e2
 }
akashche 02bc7e2
 
akashche 02bc7e2
 static jboolean
akashche 02bc7e2
@@ -1301,43 +1301,49 @@
akashche 02bc7e2
 void
akashche 02bc7e2
 debugInit_exit(jvmtiError error, const char *msg)
akashche 02bc7e2
 {
akashche 02bc7e2
-    int exit_code = 0;
akashche 02bc7e2
+    enum exit_codes { EXIT_NO_ERRORS = 0, EXIT_JVMTI_ERROR = 1, EXIT_TRANSPORT_ERROR = 2 };
akashche 02bc7e2
 
akashche 02bc7e2
-    /* Pick an error code */
akashche 02bc7e2
-    if ( error != JVMTI_ERROR_NONE ) {
akashche 02bc7e2
-        exit_code = 1;
akashche 02bc7e2
-        if ( docoredump ) {
akashche 02bc7e2
-            LOG_MISC(("Dumping core as requested by command line"));
akashche 02bc7e2
-            finish_logging(exit_code);
akashche 02bc7e2
-            abort();
akashche 02bc7e2
-        }
akashche 02bc7e2
+    // Prepare to exit. Log error and finish logging
akashche 02bc7e2
+    LOG_MISC(("Exiting with error %s(%d): %s", jvmtiErrorText(error), error,
akashche 02bc7e2
+                                               ((msg == NULL) ? "" : msg)));
akashche 02bc7e2
+
akashche 02bc7e2
+    // coredump requested by command line. Keep JVMTI data dirty
akashche 02bc7e2
+    if (error != JVMTI_ERROR_NONE && docoredump) {
akashche 02bc7e2
+        LOG_MISC(("Dumping core as requested by command line"));
akashche 02bc7e2
+        finish_logging();
akashche 02bc7e2
+        abort();
akashche 02bc7e2
     }
akashche 02bc7e2
 
akashche 02bc7e2
-    if ( msg==NULL ) {
akashche 02bc7e2
-        msg = "";
akashche 02bc7e2
-    }
akashche 02bc7e2
+    finish_logging();
akashche 02bc7e2
 
akashche 02bc7e2
-    LOG_MISC(("Exiting with error %s(%d): %s", jvmtiErrorText(error), error, msg));
akashche 02bc7e2
-
akashche 02bc7e2
+    // Cleanup the JVMTI if we have one
akashche 02bc7e2
     if (gdata != NULL) {
akashche 02bc7e2
         gdata->vmDead = JNI_TRUE;
akashche 02bc7e2
-
akashche 02bc7e2
-        /* Let's try and cleanup the JVMTI, if we even have one */
akashche 02bc7e2
-        if ( gdata->jvmti != NULL ) {
akashche 02bc7e2
-            /* Dispose of jvmti (gdata->jvmti becomes NULL) */
akashche 02bc7e2
+        if (gdata->jvmti != NULL) {
akashche 02bc7e2
+            // Dispose of jvmti (gdata->jvmti becomes NULL)
akashche 02bc7e2
             disposeEnvironment(gdata->jvmti);
akashche 02bc7e2
         }
akashche 02bc7e2
     }
akashche 02bc7e2
 
akashche 02bc7e2
-    /* Finish up logging. We reach here if JDWP is doing the exiting. */
akashche 02bc7e2
-    finish_logging(exit_code);  /* Only first call matters */
akashche 02bc7e2
-
akashche 02bc7e2
-    /* Let's give the JNI a FatalError if non-exit 0, which is historic way */
akashche 02bc7e2
-    if ( exit_code != 0 ) {
akashche 02bc7e2
-        JNIEnv *env = NULL;
akashche 02bc7e2
-        jniFatalError(env, msg, error, exit_code);
akashche 02bc7e2
+    // We are here with no errors. Kill entire process and exit with zero exit code
akashche 02bc7e2
+    if (error == JVMTI_ERROR_NONE) {
akashche 02bc7e2
+        forceExit(EXIT_NO_ERRORS);
akashche 02bc7e2
+        return;
akashche 02bc7e2
     }
akashche 02bc7e2
 
akashche 02bc7e2
-    /* Last chance to die, this kills the entire process. */
akashche 02bc7e2
-    forceExit(exit_code);
akashche 02bc7e2
+    // No transport initilized.
akashche 02bc7e2
+    // As we don't have any details here exiting with separate exit code
akashche 02bc7e2
+    if (error == AGENT_ERROR_TRANSPORT_INIT) {
akashche 02bc7e2
+        forceExit(EXIT_TRANSPORT_ERROR);
akashche 02bc7e2
+        return;
akashche 02bc7e2
+    }
akashche 02bc7e2
+
akashche 02bc7e2
+    // We have JVMTI error. Call hotspot jni_FatalError handler
akashche 02bc7e2
+    jniFatalError(NULL, msg, error, EXIT_JVMTI_ERROR);
akashche 02bc7e2
+
akashche 02bc7e2
+    // hotspot calls os:abort() so we should never reach code below,
akashche 02bc7e2
+    // but guard against possible hotspot changes
akashche 02bc7e2
+
akashche 02bc7e2
+    // Last chance to die, this kills the entire process.
akashche 02bc7e2
+    forceExit(EXIT_JVMTI_ERROR);
akashche 02bc7e2
 }
akashche 02bc7e2
diff -r 13411144d46b -r f4c9545cd8a5 src/share/back/log_messages.c
akashche 02bc7e2
--- openjdk/jdk/src/share/back/log_messages.c	Wed Jun 18 03:29:58 2014 -0700
akashche 02bc7e2
+++ openjdk/jdk/src/share/back/log_messages.c	Thu Aug 28 05:20:02 2014 -0700
akashche 02bc7e2
@@ -230,7 +230,7 @@
akashche 02bc7e2
 
akashche 02bc7e2
 /* Finish up logging, flush output to the logfile. */
akashche 02bc7e2
 void
akashche 02bc7e2
-finish_logging(int exit_code)
akashche 02bc7e2
+finish_logging()
akashche 02bc7e2
 {
akashche 02bc7e2
 #ifdef JDWP_LOGGING
akashche 02bc7e2
     MUTEX_LOCK(my_mutex);
akashche 02bc7e2
diff -r 13411144d46b -r f4c9545cd8a5 src/share/back/log_messages.h
akashche 02bc7e2
--- openjdk/jdk/src/share/back/log_messages.h	Wed Jun 18 03:29:58 2014 -0700
akashche 02bc7e2
+++ openjdk/jdk/src/share/back/log_messages.h	Thu Aug 28 05:20:02 2014 -0700
akashche 02bc7e2
@@ -29,7 +29,7 @@
akashche 02bc7e2
 /* LOG: Must be called like:  LOG_category(("anything")) or LOG_category((format,args)) */
akashche 02bc7e2
 
akashche 02bc7e2
 void setup_logging(const char *, unsigned);
akashche 02bc7e2
-void finish_logging(int);
akashche 02bc7e2
+void finish_logging();
akashche 02bc7e2
 
akashche 02bc7e2
 #define LOG_NULL ((void)0)
akashche 02bc7e2