1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
2468 void JavaThread::java_resume() {
2469 assert_locked_or_safepoint(Threads_lock);
2470
2471 // Sanity check: thread is gone, has started exiting or the thread
2472 // was not externally suspended.
2473 if (!Threads::includes(this) || is_exiting() || !is_external_suspend()) {
2474 return;
2475 }
2476
2477 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
2478
2479 clear_external_suspend();
2480
2481 if (is_ext_suspended()) {
2482 clear_ext_suspended();
2483 SR_lock()->notify_all();
2484 }
2485 }
2486
2487 void JavaThread::create_stack_guard_pages() {
2488 if (! os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) return;
2489 address low_addr = stack_base() - stack_size();
2490 size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
2491
2492 int allocate = os::allocate_stack_guard_pages();
2493 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len);
2494
2495 if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) {
2496 warning("Attempt to allocate stack guard pages failed.");
2497 return;
2498 }
2499
2500 if (os::guard_memory((char *) low_addr, len)) {
2501 _stack_guard_state = stack_guard_enabled;
2502 } else {
2503 warning("Attempt to protect stack guard pages failed.");
2504 if (os::uncommit_memory((char *) low_addr, len)) {
2505 warning("Attempt to deallocate stack guard pages failed.");
2506 }
2507 }
2508 }
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
2468 void JavaThread::java_resume() {
2469 assert_locked_or_safepoint(Threads_lock);
2470
2471 // Sanity check: thread is gone, has started exiting or the thread
2472 // was not externally suspended.
2473 if (!Threads::includes(this) || is_exiting() || !is_external_suspend()) {
2474 return;
2475 }
2476
2477 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
2478
2479 clear_external_suspend();
2480
2481 if (is_ext_suspended()) {
2482 clear_ext_suspended();
2483 SR_lock()->notify_all();
2484 }
2485 }
2486
2487 void JavaThread::create_stack_guard_pages() {
2488 if (!os::uses_stack_guard_pages() ||
2489 _stack_guard_state != stack_guard_unused ||
2490 (DisablePrimordialThreadGuardPages && os::is_primordial_thread())) {
2491 if (TraceThreadEvents) {
2492 tty->print_cr("Stack guard page creation for thread "
2493 UINTX_FORMAT " disabled", os::current_thread_id());
2494 }
2495 return;
2496 }
2497 address low_addr = stack_base() - stack_size();
2498 size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
2499
2500 int allocate = os::allocate_stack_guard_pages();
2501 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len);
2502
2503 if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) {
2504 warning("Attempt to allocate stack guard pages failed.");
2505 return;
2506 }
2507
2508 if (os::guard_memory((char *) low_addr, len)) {
2509 _stack_guard_state = stack_guard_enabled;
2510 } else {
2511 warning("Attempt to protect stack guard pages failed.");
2512 if (os::uncommit_memory((char *) low_addr, len)) {
2513 warning("Attempt to deallocate stack guard pages failed.");
2514 }
2515 }
2516 }
|