1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/windows/vm/jvm_windows.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,127 @@ 1.4 +/* 1.5 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "prims/jvm.h" 1.30 +#include "runtime/interfaceSupport.hpp" 1.31 +#include "runtime/osThread.hpp" 1.32 + 1.33 +#include <signal.h> 1.34 + 1.35 +JVM_LEAF(void*, JVM_GetThreadInterruptEvent()) 1.36 + return Thread::current()->osthread()->interrupt_event(); 1.37 +JVM_END 1.38 + 1.39 +// sun.misc.Signal /////////////////////////////////////////////////////////// 1.40 +// Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23 1.41 +/* 1.42 + * This function is included primarily as a debugging aid. If Java is 1.43 + * running in a console window, then pressing <CTRL-BREAK> will cause 1.44 + * the current state of all active threads and monitors to be written 1.45 + * to the console window. 1.46 + */ 1.47 + 1.48 +JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler)) 1.49 + // Copied from classic vm 1.50 + // signals_md.c 1.4 98/08/23 1.51 + void* newHandler = handler == (void *)2 1.52 + ? os::user_handler() 1.53 + : handler; 1.54 + switch (sig) { 1.55 + case SIGFPE: 1.56 + return (void *)-1; /* already used by VM */ 1.57 + case SIGBREAK: 1.58 + if (!ReduceSignalUsage) return (void *)-1; 1.59 + 1.60 + /* The following signals are used for Shutdown Hooks support. However, if 1.61 + ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via 1.62 + System.exit(), Java is not allowed to use these signals, and the the 1.63 + user is allowed to set his own _native_ handler for these signals and 1.64 + invoke System.exit() as needed. Terminator.setup() is avoiding 1.65 + registration of these signals when -Xrs is present. */ 1.66 + case SHUTDOWN1_SIGNAL: 1.67 + case SHUTDOWN2_SIGNAL: 1.68 + if (ReduceSignalUsage) return (void*)-1; 1.69 + } 1.70 + 1.71 + void* oldHandler = os::signal(sig, newHandler); 1.72 + if (oldHandler == os::user_handler()) { 1.73 + return (void *)2; 1.74 + } else { 1.75 + return oldHandler; 1.76 + } 1.77 +JVM_END 1.78 + 1.79 + 1.80 +JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig)) 1.81 + if (ReduceSignalUsage) { 1.82 + // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,BREAK_SIGNAL 1.83 + // to be raised when ReduceSignalUsage is set, since no handler 1.84 + // for them is actually registered in JVM or via JVM_RegisterSignal. 1.85 + if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL || 1.86 + sig == SIGBREAK) { 1.87 + return JNI_FALSE; 1.88 + } 1.89 + } 1.90 + os::signal_raise(sig); 1.91 + return JNI_TRUE; 1.92 +JVM_END 1.93 + 1.94 + 1.95 +/* 1.96 + All the defined signal names for Windows. 1.97 + 1.98 + NOTE that not all of these names are accepted by FindSignal! 1.99 + 1.100 + For various reasons some of these may be rejected at runtime. 1.101 + 1.102 + Here are the names currently accepted by a user of sun.misc.Signal with 1.103 + 1.4.1 (ignoring potential interaction with use of chaining, etc): 1.104 + 1.105 + (LIST TBD) 1.106 + 1.107 +*/ 1.108 +struct siglabel { 1.109 + char *name; 1.110 + int number; 1.111 +}; 1.112 + 1.113 +struct siglabel siglabels[] = 1.114 + /* derived from version 6.0 VC98/include/signal.h */ 1.115 + {"ABRT", SIGABRT, /* abnormal termination triggered by abort cl */ 1.116 + "FPE", SIGFPE, /* floating point exception */ 1.117 + "SEGV", SIGSEGV, /* segment violation */ 1.118 + "INT", SIGINT, /* interrupt */ 1.119 + "TERM", SIGTERM, /* software term signal from kill */ 1.120 + "BREAK", SIGBREAK, /* Ctrl-Break sequence */ 1.121 + "ILL", SIGILL}; /* illegal instruction */ 1.122 + 1.123 +JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) 1.124 + /* find and return the named signal's number */ 1.125 + 1.126 + for(int i=0;i<sizeof(siglabels)/sizeof(struct siglabel);i++) 1.127 + if(!strcmp(name, siglabels[i].name)) 1.128 + return siglabels[i].number; 1.129 + return -1; 1.130 +JVM_END