提交 4a5057cb 编写于 作者: R redestad

8068736: Avoid synchronization on Executable/Field.declaredAnnotations

Reviewed-by: jfranck, psandoz
上级 81abf70d
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -588,22 +588,29 @@ public abstract class Executable extends AccessibleObject ...@@ -588,22 +588,29 @@ public abstract class Executable extends AccessibleObject
return AnnotationParser.toArray(declaredAnnotations()); 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() { private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
if (declaredAnnotations == null) { Map<Class<? extends Annotation>, Annotation> declAnnos;
Executable root = getRoot(); if ((declAnnos = declaredAnnotations) == null) {
if (root != null) { synchronized (this) {
declaredAnnotations = root.declaredAnnotations(); if ((declAnnos = declaredAnnotations) == null) {
} else { Executable root = getRoot();
declaredAnnotations = AnnotationParser.parseAnnotations( if (root != null) {
getAnnotationBytes(), declAnnos = root.declaredAnnotations();
sun.misc.SharedSecrets.getJavaLangAccess(). } else {
getConstantPool(getDeclaringClass()), declAnnos = AnnotationParser.parseAnnotations(
getDeclaringClass()); getAnnotationBytes(),
sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
getDeclaringClass()
);
}
declaredAnnotations = declAnnos;
}
} }
} }
return declaredAnnotations; return declAnnos;
} }
/** /**
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1139,21 +1139,28 @@ class Field extends AccessibleObject implements Member { ...@@ -1139,21 +1139,28 @@ class Field extends AccessibleObject implements Member {
return AnnotationParser.toArray(declaredAnnotations()); 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() { private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
if (declaredAnnotations == null) { Map<Class<? extends Annotation>, Annotation> declAnnos;
Field root = this.root; if ((declAnnos = declaredAnnotations) == null) {
if (root != null) { synchronized (this) {
declaredAnnotations = root.declaredAnnotations(); if ((declAnnos = declaredAnnotations) == null) {
} else { Field root = this.root;
declaredAnnotations = AnnotationParser.parseAnnotations( if (root != null) {
annotations, declAnnos = root.declaredAnnotations();
sun.misc.SharedSecrets.getJavaLangAccess().getConstantPool(getDeclaringClass()), } else {
getDeclaringClass()); declAnnos = AnnotationParser.parseAnnotations(
annotations,
sun.misc.SharedSecrets.getJavaLangAccess()
.getConstantPool(getDeclaringClass()),
getDeclaringClass());
}
declaredAnnotations = declAnnos;
}
} }
} }
return declaredAnnotations; return declAnnos;
} }
private native byte[] getTypeAnnotationBytes0(); private native byte[] getTypeAnnotationBytes0();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册