8046936: JEP 270: Reserved Stack Areas for Critical Sections

Reviewed-by: acorn, dcubed
This commit is contained in:
Frederic Parain 2015-12-11 09:08:12 -08:00
parent ac45dea45e
commit 441b190d5c
3 changed files with 62 additions and 0 deletions

View File

@ -39,6 +39,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import jdk.internal.vm.annotation.ReservedStackAccess;
/**
* Provides a framework for implementing blocking locks and related
@ -886,6 +887,7 @@ public abstract class AbstractQueuedSynchronizer
* @param arg the acquire argument
* @return {@code true} if interrupted while waiting
*/
@ReservedStackAccess
final boolean acquireQueued(final Node node, int arg) {
try {
boolean interrupted = false;
@ -1218,6 +1220,7 @@ public abstract class AbstractQueuedSynchronizer
* {@link #tryAcquire} but is otherwise uninterpreted and
* can represent anything you like.
*/
@ReservedStackAccess
public final void acquire(int arg) {
if (!tryAcquire(arg) &&
acquireQueued(addWaiter(Node.EXCLUSIVE), arg))
@ -1281,6 +1284,7 @@ public abstract class AbstractQueuedSynchronizer
* can represent anything you like.
* @return the value returned from {@link #tryRelease}
*/
@ReservedStackAccess
public final boolean release(int arg) {
if (tryRelease(arg)) {
Node h = head;
@ -1361,6 +1365,7 @@ public abstract class AbstractQueuedSynchronizer
* and can represent anything you like.
* @return the value returned from {@link #tryReleaseShared}
*/
@ReservedStackAccess
public final boolean releaseShared(int arg) {
if (tryReleaseShared(arg)) {
doReleaseShared();

View File

@ -37,6 +37,7 @@ package java.util.concurrent.locks;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import jdk.internal.vm.annotation.ReservedStackAccess;
/**
* A reentrant mutual exclusion {@link Lock} with the same basic
@ -127,6 +128,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* Performs non-fair tryLock. tryAcquire is implemented in
* subclasses, but both need nonfair try for trylock method.
*/
@ReservedStackAccess
final boolean nonfairTryAcquire(int acquires) {
final Thread current = Thread.currentThread();
int c = getState();
@ -146,6 +148,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
return false;
}
@ReservedStackAccess
protected final boolean tryRelease(int releases) {
int c = getState() - releases;
if (Thread.currentThread() != getExclusiveOwnerThread())
@ -203,6 +206,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* Performs lock. Try immediate barge, backing up to normal
* acquire on failure.
*/
@ReservedStackAccess
final void lock() {
if (compareAndSetState(0, 1))
setExclusiveOwnerThread(Thread.currentThread());
@ -229,6 +233,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* Fair version of tryAcquire. Don't grant access unless
* recursive call or no waiters or is first.
*/
@ReservedStackAccess
protected final boolean tryAcquire(int acquires) {
final Thread current = Thread.currentThread();
int c = getState();

View File

@ -0,0 +1,52 @@
/*
* 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.
*/
package jdk.internal.vm.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* <p>An annotation expressing that a method is especially sensitive
* to stack overflows. This is a hint the JVM can use to grant access to
* extra stack space when executing this code if such feature is supported
* by the JVM. The JVM is free to ignore this annotation.
*
* A possible way for the JVM to improve the execution context for methods
* with this annotation is to reserve part of the thread's execution stack
* for them. Access to this section of the stack would be denied by default
* but could be granted if the JVM detects a possible stack overflow and
* the thread's call stack includes at least one annotated method. Even if
* access to this reserved area has been granted, the JVM might decide to
* throw a delayed StackOverflowError when the thread exits the annotated
* method.
*
* @since 1.9
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})
public @interface ReservedStackAccess { }