8068736: Avoid synchronization on Executable/Field.declaredAnnotations
Reviewed-by: jfranck, psandoz
This commit is contained in:
parent
c0500545f7
commit
31f50fcff9
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 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
|
||||
@ -588,22 +588,29 @@ public abstract class Executable extends AccessibleObject
|
||||
return AnnotationParser.toArray(declaredAnnotations());
|
||||
}
|
||||
|
||||
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||
private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||
|
||||
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||
if (declaredAnnotations == null) {
|
||||
Executable root = getRoot();
|
||||
if (root != null) {
|
||||
declaredAnnotations = root.declaredAnnotations();
|
||||
} else {
|
||||
declaredAnnotations = AnnotationParser.parseAnnotations(
|
||||
getAnnotationBytes(),
|
||||
sun.misc.SharedSecrets.getJavaLangAccess().
|
||||
getConstantPool(getDeclaringClass()),
|
||||
getDeclaringClass());
|
||||
private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||
Map<Class<? extends Annotation>, Annotation> declAnnos;
|
||||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
synchronized (this) {
|
||||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
Executable root = getRoot();
|
||||
if (root != null) {
|
||||
declAnnos = root.declaredAnnotations();
|
||||
} else {
|
||||
declAnnos = AnnotationParser.parseAnnotations(
|
||||
getAnnotationBytes(),
|
||||
sun.misc.SharedSecrets.getJavaLangAccess().
|
||||
getConstantPool(getDeclaringClass()),
|
||||
getDeclaringClass()
|
||||
);
|
||||
}
|
||||
declaredAnnotations = declAnnos;
|
||||
}
|
||||
}
|
||||
}
|
||||
return declaredAnnotations;
|
||||
return declAnnos;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 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
|
||||
@ -1139,21 +1139,28 @@ class Field extends AccessibleObject implements Member {
|
||||
return AnnotationParser.toArray(declaredAnnotations());
|
||||
}
|
||||
|
||||
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||
private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||
|
||||
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||
if (declaredAnnotations == null) {
|
||||
Field root = this.root;
|
||||
if (root != null) {
|
||||
declaredAnnotations = root.declaredAnnotations();
|
||||
} else {
|
||||
declaredAnnotations = AnnotationParser.parseAnnotations(
|
||||
annotations,
|
||||
sun.misc.SharedSecrets.getJavaLangAccess().getConstantPool(getDeclaringClass()),
|
||||
getDeclaringClass());
|
||||
private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||
Map<Class<? extends Annotation>, Annotation> declAnnos;
|
||||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
synchronized (this) {
|
||||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
Field root = this.root;
|
||||
if (root != null) {
|
||||
declAnnos = root.declaredAnnotations();
|
||||
} else {
|
||||
declAnnos = AnnotationParser.parseAnnotations(
|
||||
annotations,
|
||||
sun.misc.SharedSecrets.getJavaLangAccess()
|
||||
.getConstantPool(getDeclaringClass()),
|
||||
getDeclaringClass());
|
||||
}
|
||||
declaredAnnotations = declAnnos;
|
||||
}
|
||||
}
|
||||
}
|
||||
return declaredAnnotations;
|
||||
return declAnnos;
|
||||
}
|
||||
|
||||
private native byte[] getTypeAnnotationBytes0();
|
||||
|
Loading…
x
Reference in New Issue
Block a user