|
1 | 1 | /* |
2 | | - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -562,6 +562,11 @@ int JVM_HANDLE_XXX_SIGNAL(int sig, siginfo_t* info, |
562 | 562 | { |
563 | 563 | assert(info != NULL && ucVoid != NULL, "sanity"); |
564 | 564 |
|
| 565 | + if (sig == BREAK_SIGNAL) { |
| 566 | + assert(!ReduceSignalUsage, "Should not happen with -Xrs/-XX:+ReduceSignalUsage"); |
| 567 | + return true; // ignore it |
| 568 | + } |
| 569 | + |
565 | 570 | // Note: it's not uncommon that JNI code uses signal/sigset to install, |
566 | 571 | // then restore certain signal handler (e.g. to temporarily block SIGPIPE, |
567 | 572 | // or have a SIGILL handler when detecting CPU type). When that happens, |
@@ -1197,7 +1202,7 @@ int os::get_signal_number(const char* signal_name) { |
1197 | 1202 | return -1; |
1198 | 1203 | } |
1199 | 1204 |
|
1200 | | -void set_signal_handler(int sig) { |
| 1205 | +void set_signal_handler(int sig, bool do_check = true) { |
1201 | 1206 | // Check for overwrite. |
1202 | 1207 | struct sigaction oldAct; |
1203 | 1208 | sigaction(sig, (struct sigaction*)NULL, &oldAct); |
@@ -1241,7 +1246,7 @@ void set_signal_handler(int sig) { |
1241 | 1246 |
|
1242 | 1247 | // Save handler setup for later checking |
1243 | 1248 | vm_handlers.set(sig, &sigAct); |
1244 | | - do_check_signal_periodically[sig] = true; |
| 1249 | + do_check_signal_periodically[sig] = do_check; |
1245 | 1250 |
|
1246 | 1251 | int ret = sigaction(sig, &sigAct, &oldAct); |
1247 | 1252 | assert(ret == 0, "check"); |
@@ -1279,7 +1284,12 @@ void install_signal_handlers() { |
1279 | 1284 | set_signal_handler(SIGFPE); |
1280 | 1285 | PPC64_ONLY(set_signal_handler(SIGTRAP);) |
1281 | 1286 | set_signal_handler(SIGXFSZ); |
1282 | | - |
| 1287 | + if (!ReduceSignalUsage) { |
| 1288 | + // This is just for early initialization phase. Intercepting the signal here reduces the risk |
| 1289 | + // that an attach client accidentally forces HotSpot to quit prematurely. We skip the periodic |
| 1290 | + // check because late initialization will overwrite it to UserHandler. |
| 1291 | + set_signal_handler(BREAK_SIGNAL, false); |
| 1292 | + } |
1283 | 1293 | #if defined(__APPLE__) |
1284 | 1294 | // lldb (gdb) installs both standard BSD signal handlers, and mach exception |
1285 | 1295 | // handlers. By replacing the existing task exception handler, we disable lldb's mach |
|
0 commit comments