changeset 9535:b43a5bd9cbb1 jdk-9+102

Merge
author kcr
date Tue, 19 Jan 2016 09:01:53 -0800
parents 64f4605ad7b7 cf024b0fadca
children 3aca15177d16 0baf599539de 2c352db07fb1
files
diffstat 6 files changed, 171 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/media/src/main/native/jfxmedia/MediaManagement/MediaManager.cpp	Tue Jan 19 11:02:33 2016 +1300
+++ b/modules/media/src/main/native/jfxmedia/MediaManagement/MediaManager.cpp	Tue Jan 19 09:01:53 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015, 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
@@ -34,6 +34,10 @@
 #include <Utils/JfxCriticalSection.h>
 #include <jfxmedia_errors.h>
 
+#if TARGET_OS_WIN32
+#include <Utils/win32/WinExceptionHandler.h>
+#endif
+
 CMediaManager::MMSingleton CMediaManager::s_Singleton;
 
 //*************************************************************************************************
@@ -74,6 +78,10 @@
 #if !defined(TARGET_OS_WIN32) && !defined(TARGET_OS_MAC) && !defined(TARGET_OS_LINUX)
     return ERROR_OS_UNSUPPORTED;
 #else
+#if TARGET_OS_WIN32
+    SetExceptionHandler();
+#endif
+
     CGstMediaManager* pGstManager = new(nothrow) CGstMediaManager();
     if (NULL == pGstManager)
         return ERROR_MEMORY_ALLOCATION;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/media/src/main/native/jfxmedia/Utils/win32/WinExceptionHandler.cpp	Tue Jan 19 09:01:53 2016 -0800
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <Windows.h>
+#include <string.h>
+#include <Strsafe.h>
+
+#include <gst/gst.h>
+
+#include <Utils/win32/WinExceptionHandler.h>
+
+#define BUFFER_SIZE 1024
+
+static bool isFile = false;
+static bool isConsole = false;
+static bool disableDefaultHandler = false;
+
+void LogMessage(HANDLE hFile, char *buffer)
+{
+    DWORD written = 0;
+
+    if (isFile && hFile != INVALID_HANDLE_VALUE)
+        WriteFile(hFile, buffer, strlen(buffer), &written, NULL);
+
+    if (isConsole)
+        g_print(buffer);
+}
+
+HANDLE GetFileHandle()
+{
+    if (!isFile)
+        return INVALID_HANDLE_VALUE;
+
+    TCHAR buffer[MAX_PATH] = {0};
+    HANDLE hFile = INVALID_HANDLE_VALUE;
+    DWORD pid = GetCurrentProcessId();
+    
+    HRESULT hr = StringCchPrintf(buffer, MAX_PATH, "jfxm_err_pid%d.log", pid);
+    if (FAILED(hr))
+        return INVALID_HANDLE_VALUE;
+    
+    return CreateFile(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+}
+
+LONG WINAPI JFXMUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo)
+{
+    HANDLE hFile = INVALID_HANDLE_VALUE;
+    char buffer[BUFFER_SIZE] = {0};
+    HRESULT hr = S_OK;
+
+    hFile = GetFileHandle();
+
+    LogMessage(hFile, "#\n");
+    LogMessage(hFile, "# A fatal error has been detected by the JavaFX Media Runtime:\n");
+    LogMessage(hFile, "#\n");
+
+    if (ExceptionInfo && ExceptionInfo->ExceptionRecord)
+    {
+        hr = StringCchPrintf(buffer, BUFFER_SIZE, "# Exception Code: 0x%X Exception Address: 0x%p\n", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress);
+        if (SUCCEEDED(hr))
+        {
+            LogMessage(hFile, buffer);
+        }
+    }
+
+    if (hFile != INVALID_HANDLE_VALUE)
+        CloseHandle(hFile);
+
+    if (disableDefaultHandler)
+        return EXCEPTION_EXECUTE_HANDLER;
+
+    return EXCEPTION_CONTINUE_SEARCH;
+}
+
+bool GetSettings(char *var)
+{
+    TCHAR buffer[MAX_PATH] = {0};
+
+    DWORD dwRet = GetEnvironmentVariable(var, buffer, MAX_PATH);
+    if (dwRet == 1 && buffer[0] == '1')
+        return true;
+
+    return false;
+}
+
+void SetExceptionHandler()
+{
+    isFile = GetSettings("JFXM_EXCEPTION_HANDLER_FILE");
+    isConsole = GetSettings("JFXM_EXCEPTION_HANDLER_CONSOLE");
+
+    if (isFile || isConsole)
+    {
+        disableDefaultHandler = GetSettings("JFXM_EXCEPTION_DISABLE_DEFAULT_HANDLER");
+        SetUnhandledExceptionFilter(JFXMUnhandledExceptionFilter);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/media/src/main/native/jfxmedia/Utils/win32/WinExceptionHandler.h	Tue Jan 19 09:01:53 2016 -0800
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef _WIN_EXCEPTION_HANDLER_H_
+#define _WIN_EXCEPTION_HANDLER_H_
+
+// Registers exception handler if needed.
+// To enable exception handler set JFXM_EXCEPTION_HANDLER_FILE and/or JFXM_EXCEPTION_HANDLER_CONSOLE environment variables to 1.
+// To disable default exception handler when media exception handler is enabled set JFXM_EXCEPTION_DISABLE_DEFAULT_HANDLER to 1.
+void SetExceptionHandler();
+
+#endif // _WIN_EXCEPTION_HANDLER_H_
--- a/modules/media/src/main/native/jfxmedia/projects/win/Makefile	Tue Jan 19 11:02:33 2016 +1300
+++ b/modules/media/src/main/native/jfxmedia/projects/win/Makefile	Tue Jan 19 09:01:53 2016 -0800
@@ -134,7 +134,8 @@
         Utils/LowLevelPerf.cpp \
         Utils/win32/WinCriticalSection.cpp  \
         Utils/win32/WinDllMain.cpp \
-        Utils/win32/WinThread.cpp
+        Utils/win32/WinThread.cpp \
+        Utils/win32/WinExceptionHandler.cpp
 
 C_SOURCES = Utils/ColorConverter.c
 
--- a/modules/media/src/main/native/vs_project/jfxmedia/jfxmedia.vcxproj	Tue Jan 19 11:02:33 2016 +1300
+++ b/modules/media/src/main/native/vs_project/jfxmedia/jfxmedia.vcxproj	Tue Jan 19 09:01:53 2016 -0800
@@ -52,6 +52,7 @@
     <ClCompile Include="..\..\jfxmedia\Utils\MediaWarningDispatcher.cpp" />
     <ClCompile Include="..\..\jfxmedia\Utils\win32\WinCriticalSection.cpp" />
     <ClCompile Include="..\..\jfxmedia\Utils\win32\WinDllMain.cpp" />
+    <ClCompile Include="..\..\jfxmedia\Utils\win32\WinExceptionHandler.cpp" />
     <ClCompile Include="..\..\jfxmedia\Utils\win32\WinThread.cpp" />
   </ItemGroup>
   <ItemGroup>
@@ -93,6 +94,7 @@
     <ClInclude Include="..\..\jfxmedia\Utils\MediaWarningDispatcher.h" />
     <ClInclude Include="..\..\jfxmedia\Utils\Singleton.h" />
     <ClInclude Include="..\..\jfxmedia\Utils\Thread.h" />
+    <ClInclude Include="..\..\jfxmedia\Utils\win32\WinExceptionHandler.h" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{41E7B612-A478-4FD5-9B2D-1B591FC6EE8A}</ProjectGuid>
--- a/modules/media/src/main/native/vs_project/jfxmedia/jfxmedia.vcxproj.filters	Tue Jan 19 11:02:33 2016 +1300
+++ b/modules/media/src/main/native/vs_project/jfxmedia/jfxmedia.vcxproj.filters	Tue Jan 19 09:01:53 2016 -0800
@@ -153,6 +153,9 @@
     <ClCompile Include="..\..\jfxmedia\jni\NativeEqualizerBand.cpp">
       <Filter>jni</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\jfxmedia\Utils\win32\WinExceptionHandler.cpp">
+      <Filter>Utils\win32</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\jfxmedia\jni\JavaBandsHolder.h">
@@ -269,5 +272,8 @@
     <ClInclude Include="..\..\jfxmedia\platform\gstreamer\GstVideoFrame.h">
       <Filter>platform\gstreamer</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\jfxmedia\Utils\win32\WinExceptionHandler.h">
+      <Filter>Utils\win32</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file