src/os/windows/vm/jvm_windows.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "prims/jvm.h"
aoqi@0 27 #include "runtime/interfaceSupport.hpp"
aoqi@0 28 #include "runtime/osThread.hpp"
aoqi@0 29
aoqi@0 30 #include <signal.h>
aoqi@0 31
aoqi@0 32 JVM_LEAF(void*, JVM_GetThreadInterruptEvent())
aoqi@0 33 return Thread::current()->osthread()->interrupt_event();
aoqi@0 34 JVM_END
aoqi@0 35
aoqi@0 36 // sun.misc.Signal ///////////////////////////////////////////////////////////
aoqi@0 37 // Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23
aoqi@0 38 /*
aoqi@0 39 * This function is included primarily as a debugging aid. If Java is
aoqi@0 40 * running in a console window, then pressing <CTRL-BREAK> will cause
aoqi@0 41 * the current state of all active threads and monitors to be written
aoqi@0 42 * to the console window.
aoqi@0 43 */
aoqi@0 44
aoqi@0 45 JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
aoqi@0 46 // Copied from classic vm
aoqi@0 47 // signals_md.c 1.4 98/08/23
aoqi@0 48 void* newHandler = handler == (void *)2
aoqi@0 49 ? os::user_handler()
aoqi@0 50 : handler;
aoqi@0 51 switch (sig) {
aoqi@0 52 case SIGFPE:
aoqi@0 53 return (void *)-1; /* already used by VM */
aoqi@0 54 case SIGBREAK:
aoqi@0 55 if (!ReduceSignalUsage) return (void *)-1;
aoqi@0 56
aoqi@0 57 /* The following signals are used for Shutdown Hooks support. However, if
aoqi@0 58 ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
aoqi@0 59 System.exit(), Java is not allowed to use these signals, and the the
aoqi@0 60 user is allowed to set his own _native_ handler for these signals and
aoqi@0 61 invoke System.exit() as needed. Terminator.setup() is avoiding
aoqi@0 62 registration of these signals when -Xrs is present. */
aoqi@0 63 case SHUTDOWN1_SIGNAL:
aoqi@0 64 case SHUTDOWN2_SIGNAL:
aoqi@0 65 if (ReduceSignalUsage) return (void*)-1;
aoqi@0 66 }
aoqi@0 67
aoqi@0 68 void* oldHandler = os::signal(sig, newHandler);
aoqi@0 69 if (oldHandler == os::user_handler()) {
aoqi@0 70 return (void *)2;
aoqi@0 71 } else {
aoqi@0 72 return oldHandler;
aoqi@0 73 }
aoqi@0 74 JVM_END
aoqi@0 75
aoqi@0 76
aoqi@0 77 JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
aoqi@0 78 if (ReduceSignalUsage) {
aoqi@0 79 // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,BREAK_SIGNAL
aoqi@0 80 // to be raised when ReduceSignalUsage is set, since no handler
aoqi@0 81 // for them is actually registered in JVM or via JVM_RegisterSignal.
aoqi@0 82 if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
aoqi@0 83 sig == SIGBREAK) {
aoqi@0 84 return JNI_FALSE;
aoqi@0 85 }
aoqi@0 86 }
aoqi@0 87 os::signal_raise(sig);
aoqi@0 88 return JNI_TRUE;
aoqi@0 89 JVM_END
aoqi@0 90
aoqi@0 91
aoqi@0 92 /*
aoqi@0 93 All the defined signal names for Windows.
aoqi@0 94
aoqi@0 95 NOTE that not all of these names are accepted by FindSignal!
aoqi@0 96
aoqi@0 97 For various reasons some of these may be rejected at runtime.
aoqi@0 98
aoqi@0 99 Here are the names currently accepted by a user of sun.misc.Signal with
aoqi@0 100 1.4.1 (ignoring potential interaction with use of chaining, etc):
aoqi@0 101
aoqi@0 102 (LIST TBD)
aoqi@0 103
aoqi@0 104 */
aoqi@0 105 struct siglabel {
aoqi@0 106 char *name;
aoqi@0 107 int number;
aoqi@0 108 };
aoqi@0 109
aoqi@0 110 struct siglabel siglabels[] =
aoqi@0 111 /* derived from version 6.0 VC98/include/signal.h */
aoqi@0 112 {"ABRT", SIGABRT, /* abnormal termination triggered by abort cl */
aoqi@0 113 "FPE", SIGFPE, /* floating point exception */
aoqi@0 114 "SEGV", SIGSEGV, /* segment violation */
aoqi@0 115 "INT", SIGINT, /* interrupt */
aoqi@0 116 "TERM", SIGTERM, /* software term signal from kill */
aoqi@0 117 "BREAK", SIGBREAK, /* Ctrl-Break sequence */
aoqi@0 118 "ILL", SIGILL}; /* illegal instruction */
aoqi@0 119
aoqi@0 120 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
aoqi@0 121 /* find and return the named signal's number */
aoqi@0 122
aoqi@0 123 for(int i=0;i<sizeof(siglabels)/sizeof(struct siglabel);i++)
aoqi@0 124 if(!strcmp(name, siglabels[i].name))
aoqi@0 125 return siglabels[i].number;
aoqi@0 126 return -1;
aoqi@0 127 JVM_END

mercurial