changeset 49022:f413e471a6ab

8041626: Shutdown tracing event Reviewed-by: dholmes, alanb, rriggs
author rwestberg
date Tue, 13 Feb 2018 15:48:23 +0100
parents 6a5decfc5574
children eebf559c9e0d
files make/hotspot/symbols/symbols-unix make/mapfiles/libjava/mapfile-vers src/hotspot/share/include/jvm.h src/hotspot/share/prims/jvm.cpp src/hotspot/share/runtime/thread.cpp src/hotspot/share/trace/traceevents.xml src/hotspot/share/utilities/vmError.cpp src/java.base/share/classes/java/lang/Runtime.java src/java.base/share/classes/java/lang/Shutdown.java src/java.base/share/native/libjava/Shutdown.c
diffstat 10 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/make/hotspot/symbols/symbols-unix	Tue Feb 27 14:15:30 2018 +0100
+++ b/make/hotspot/symbols/symbols-unix	Tue Feb 13 15:48:23 2018 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
 JVM_ActiveProcessorCount
 JVM_ArrayCopy
 JVM_AssertionStatusDirectives
+JVM_BeforeHalt
 JVM_CallStackWalk
 JVM_Clone
 JVM_ConstantPoolGetClassAt
--- a/make/mapfiles/libjava/mapfile-vers	Tue Feb 27 14:15:30 2018 +0100
+++ b/make/mapfiles/libjava/mapfile-vers	Tue Feb 13 15:48:23 2018 +0100
@@ -207,6 +207,7 @@
 		Java_java_lang_Runtime_totalMemory;
 		Java_java_lang_Runtime_availableProcessors;
 		Java_java_lang_SecurityManager_getClassContext;
+		Java_java_lang_Shutdown_beforeHalt;
 		Java_java_lang_Shutdown_halt0;
                 Java_java_lang_StackTraceElement_initStackTraceElement;
                 Java_java_lang_StackTraceElement_initStackTraceElements;
--- a/src/hotspot/share/include/jvm.h	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/hotspot/share/include/jvm.h	Tue Feb 13 15:48:23 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -119,6 +119,9 @@
  * java.lang.Runtime
  */
 JNIEXPORT void JNICALL
+JVM_BeforeHalt();
+
+JNIEXPORT void JNICALL
 JVM_Halt(jint code);
 
 JNIEXPORT void JNICALL
--- a/src/hotspot/share/prims/jvm.cpp	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/hotspot/share/prims/jvm.cpp	Tue Feb 13 15:48:23 2018 +0100
@@ -434,6 +434,16 @@
 
 extern volatile jint vm_created;
 
+JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
+  JVMWrapper("JVM_BeforeHalt");
+  EventShutdown event;
+  if (event.should_commit()) {
+    event.set_reason("Shutdown requested from Java");
+    event.commit();
+  }
+JVM_END
+
+
 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
   before_exit(thread);
   vm_exit(code);
--- a/src/hotspot/share/runtime/thread.cpp	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/hotspot/share/runtime/thread.cpp	Tue Feb 13 15:48:23 2018 +0100
@@ -4216,6 +4216,12 @@
                          Mutex::_as_suspend_equivalent_flag);
   }
 
+  EventShutdown e;
+  if (e.should_commit()) {
+    e.set_reason("No remaining non-daemon Java threads");
+    e.commit();
+  }
+
   // Hang forever on exit if we are reporting an error.
   if (ShowMessageBoxOnError && VMError::is_error_reported()) {
     os::infinite_sleep();
--- a/src/hotspot/share/trace/traceevents.xml	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/hotspot/share/trace/traceevents.xml	Tue Feb 13 15:48:23 2018 +0100
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
- Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
  This code is free software; you can redistribute it and/or modify it
@@ -628,6 +628,11 @@
     <value type="INTEGER" field="safepointId" label="Safepoint Identifier" description="The safepoint (if any) under which this operation was completed" relation="SafepointId"/>
   </event>
 
+  <event id="Shutdown" path="vm/runtime/shutdown" label="VM Shutdown"
+         description="VM shutting down" has_thread="true" has_stacktrace="true" is_instant="true">
+    <value type="STRING" field="reason" label="Reason" description="Reason for VM shutdown"/>
+  </event>
+
   <!-- Allocation events -->
   <event id="ObjectAllocationInNewTLAB" path="java/object_alloc_in_new_TLAB" label="Allocation in new TLAB"
          description="Allocation in new Thread Local Allocation Buffer" has_thread="true" has_stacktrace="true" is_instant="true">
--- a/src/hotspot/share/utilities/vmError.cpp	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/hotspot/share/utilities/vmError.cpp	Tue Feb 13 15:48:23 2018 +0100
@@ -1305,6 +1305,12 @@
     // are handled properly.
     reset_signal_handlers();
 
+    EventShutdown e;
+    if (e.should_commit()) {
+      e.set_reason("VM Error");
+      e.commit();
+    }
+
     TRACE_VM_ERROR();
 
   } else {
--- a/src/java.base/share/classes/java/lang/Runtime.java	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/java.base/share/classes/java/lang/Runtime.java	Tue Feb 13 15:48:23 2018 +0100
@@ -280,6 +280,7 @@
         if (sm != null) {
             sm.checkExit(status);
         }
+        Shutdown.beforeHalt();
         Shutdown.halt(status);
     }
 
--- a/src/java.base/share/classes/java/lang/Shutdown.java	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/java.base/share/classes/java/lang/Shutdown.java	Tue Feb 13 15:48:23 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -130,6 +130,9 @@
         }
     }
 
+    /* Notify the VM that it's time to halt. */
+    static native void beforeHalt();
+
     /* The halt method is synchronized on the halt lock
      * to avoid corruption of the delete-on-shutdown file list.
      * It invokes the true native halt method.
@@ -209,6 +212,7 @@
             /* Synchronize on the class object, causing any other thread
              * that attempts to initiate shutdown to stall indefinitely
              */
+            beforeHalt();
             sequence();
             halt(status);
         }
--- a/src/java.base/share/native/libjava/Shutdown.c	Tue Feb 27 14:15:30 2018 +0100
+++ b/src/java.base/share/native/libjava/Shutdown.c	Tue Feb 13 15:48:23 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,11 @@
 
 #include "java_lang_Shutdown.h"
 
+JNIEXPORT void JNICALL
+Java_java_lang_Shutdown_beforeHalt(JNIEnv *env, jclass ignored)
+{
+    JVM_BeforeHalt();
+}
 
 JNIEXPORT void JNICALL
 Java_java_lang_Shutdown_halt0(JNIEnv *env, jclass ignored, jint code)