提交 e122507b 编写于 作者: J jfranck

8009719: core reflection should get type annotation data from the VM lazily

Summary: Remove typeAnnotations field from Method, Constructor, and Field, update  Executable and Field to fetch data on demand.
Reviewed-by: darcy, erikj
上级 0ecf4bb6
...@@ -33,6 +33,7 @@ FILES_c = \ ...@@ -33,6 +33,7 @@ FILES_c = \
Console_md.c \ Console_md.c \
Double.c \ Double.c \
Executable.c \ Executable.c \
Field.c \
FileDescriptor_md.c \ FileDescriptor_md.c \
FileInputStream.c \ FileInputStream.c \
FileInputStream_md.c \ FileInputStream_md.c \
......
...@@ -190,6 +190,8 @@ SUNWprivate_1.1 { ...@@ -190,6 +190,8 @@ SUNWprivate_1.1 {
Java_java_lang_reflect_Array_setLong; Java_java_lang_reflect_Array_setLong;
Java_java_lang_reflect_Array_setShort; Java_java_lang_reflect_Array_setShort;
Java_java_lang_reflect_Executable_getParameters0; Java_java_lang_reflect_Executable_getParameters0;
Java_java_lang_reflect_Executable_getTypeAnnotationBytes0;
Java_java_lang_reflect_Field_getTypeAnnotationBytes0;
Java_java_lang_Runtime_freeMemory; Java_java_lang_Runtime_freeMemory;
Java_java_lang_Runtime_maxMemory; Java_java_lang_Runtime_maxMemory;
Java_java_lang_Runtime_gc; Java_java_lang_Runtime_gc;
......
...@@ -190,6 +190,8 @@ SUNWprivate_1.1 { ...@@ -190,6 +190,8 @@ SUNWprivate_1.1 {
Java_java_lang_reflect_Array_setLong; Java_java_lang_reflect_Array_setLong;
Java_java_lang_reflect_Array_setShort; Java_java_lang_reflect_Array_setShort;
Java_java_lang_reflect_Executable_getParameters0; Java_java_lang_reflect_Executable_getParameters0;
Java_java_lang_reflect_Executable_getTypeAnnotationBytes0;
Java_java_lang_reflect_Field_getTypeAnnotationBytes0;
Java_java_lang_Runtime_freeMemory; Java_java_lang_Runtime_freeMemory;
Java_java_lang_Runtime_maxMemory; Java_java_lang_Runtime_maxMemory;
Java_java_lang_Runtime_gc; Java_java_lang_Runtime_gc;
......
...@@ -67,8 +67,6 @@ public final class Constructor<T> extends Executable { ...@@ -67,8 +67,6 @@ public final class Constructor<T> extends Executable {
private transient ConstructorRepository genericInfo; private transient ConstructorRepository genericInfo;
private byte[] annotations; private byte[] annotations;
private byte[] parameterAnnotations; private byte[] parameterAnnotations;
// This is set by the vm at Constructor creation
private byte[] typeAnnotations;
// Generics infrastructure // Generics infrastructure
// Accessor for factory // Accessor for factory
...@@ -141,8 +139,6 @@ public final class Constructor<T> extends Executable { ...@@ -141,8 +139,6 @@ public final class Constructor<T> extends Executable {
res.root = this; res.root = this;
// Might as well eagerly propagate this if already present // Might as well eagerly propagate this if already present
res.constructorAccessor = constructorAccessor; res.constructorAccessor = constructorAccessor;
res.typeAnnotations = typeAnnotations;
return res; return res;
} }
...@@ -155,10 +151,6 @@ public final class Constructor<T> extends Executable { ...@@ -155,10 +151,6 @@ public final class Constructor<T> extends Executable {
byte[] getAnnotationBytes() { byte[] getAnnotationBytes() {
return annotations; return annotations;
} }
@Override
byte[] getTypeAnnotationBytes() {
return typeAnnotations;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
......
...@@ -51,7 +51,6 @@ public abstract class Executable extends AccessibleObject ...@@ -51,7 +51,6 @@ public abstract class Executable extends AccessibleObject
* Accessor method to allow code sharing * Accessor method to allow code sharing
*/ */
abstract byte[] getAnnotationBytes(); abstract byte[] getAnnotationBytes();
abstract byte[] getTypeAnnotationBytes();
/** /**
* Does the Executable have generic information. * Does the Executable have generic information.
...@@ -352,6 +351,12 @@ public abstract class Executable extends AccessibleObject ...@@ -352,6 +351,12 @@ public abstract class Executable extends AccessibleObject
private transient volatile Parameter[] parameters; private transient volatile Parameter[] parameters;
private native Parameter[] getParameters0(); private native Parameter[] getParameters0();
private native byte[] getTypeAnnotationBytes0();
// Needed by reflectaccess
byte[] getTypeAnnotationBytes() {
return getTypeAnnotationBytes0();
}
/** /**
* Returns an array of {@code Class} objects that represent the * Returns an array of {@code Class} objects that represent the
...@@ -541,7 +546,7 @@ public abstract class Executable extends AccessibleObject ...@@ -541,7 +546,7 @@ public abstract class Executable extends AccessibleObject
* @since 1.8 * @since 1.8
*/ */
AnnotatedType getAnnotatedReturnType0(Type returnType) { AnnotatedType getAnnotatedReturnType0(Type returnType) {
return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(), return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
sun.misc.SharedSecrets.getJavaLangAccess(). sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()), getConstantPool(getDeclaringClass()),
this, this,
...@@ -574,7 +579,7 @@ public abstract class Executable extends AccessibleObject ...@@ -574,7 +579,7 @@ public abstract class Executable extends AccessibleObject
public AnnotatedType getAnnotatedReceiverType() { public AnnotatedType getAnnotatedReceiverType() {
if (Modifier.isStatic(this.getModifiers())) if (Modifier.isStatic(this.getModifiers()))
return null; return null;
return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(), return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
sun.misc.SharedSecrets.getJavaLangAccess(). sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()), getConstantPool(getDeclaringClass()),
this, this,
...@@ -600,7 +605,7 @@ public abstract class Executable extends AccessibleObject ...@@ -600,7 +605,7 @@ public abstract class Executable extends AccessibleObject
* @since 1.8 * @since 1.8
*/ */
public AnnotatedType[] getAnnotatedParameterTypes() { public AnnotatedType[] getAnnotatedParameterTypes() {
return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes(), return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
sun.misc.SharedSecrets.getJavaLangAccess(). sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()), getConstantPool(getDeclaringClass()),
this, this,
...@@ -626,7 +631,7 @@ public abstract class Executable extends AccessibleObject ...@@ -626,7 +631,7 @@ public abstract class Executable extends AccessibleObject
* @since 1.8 * @since 1.8
*/ */
public AnnotatedType[] getAnnotatedExceptionTypes() { public AnnotatedType[] getAnnotatedExceptionTypes() {
return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes(), return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
sun.misc.SharedSecrets.getJavaLangAccess(). sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()), getConstantPool(getDeclaringClass()),
this, this,
......
...@@ -82,8 +82,6 @@ class Field extends AccessibleObject implements Member { ...@@ -82,8 +82,6 @@ class Field extends AccessibleObject implements Member {
// currently only two levels deep (i.e., one root Field and // currently only two levels deep (i.e., one root Field and
// potentially many Field objects pointing to it.) // potentially many Field objects pointing to it.)
private Field root; private Field root;
// This is set by the vm at Field creation
private byte[] typeAnnotations;
// Generics infrastructure // Generics infrastructure
...@@ -149,7 +147,6 @@ class Field extends AccessibleObject implements Member { ...@@ -149,7 +147,6 @@ class Field extends AccessibleObject implements Member {
res.fieldAccessor = fieldAccessor; res.fieldAccessor = fieldAccessor;
res.overrideFieldAccessor = overrideFieldAccessor; res.overrideFieldAccessor = overrideFieldAccessor;
res.typeAnnotations = typeAnnotations;
return res; return res;
} }
...@@ -1148,6 +1145,8 @@ class Field extends AccessibleObject implements Member { ...@@ -1148,6 +1145,8 @@ class Field extends AccessibleObject implements Member {
return declaredAnnotations; return declaredAnnotations;
} }
private native byte[] getTypeAnnotationBytes0();
/** /**
* Returns an AnnotatedType object that represents the use of a type to specify * Returns an AnnotatedType object that represents the use of a type to specify
* the declared type of the field represented by this Field. * the declared type of the field represented by this Field.
...@@ -1157,7 +1156,7 @@ class Field extends AccessibleObject implements Member { ...@@ -1157,7 +1156,7 @@ class Field extends AccessibleObject implements Member {
* @since 1.8 * @since 1.8
*/ */
public AnnotatedType getAnnotatedType() { public AnnotatedType getAnnotatedType() {
return TypeAnnotationParser.buildAnnotatedType(typeAnnotations, return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
sun.misc.SharedSecrets.getJavaLangAccess(). sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()), getConstantPool(getDeclaringClass()),
this, this,
......
...@@ -80,8 +80,6 @@ public final class Method extends Executable { ...@@ -80,8 +80,6 @@ public final class Method extends Executable {
// currently only two levels deep (i.e., one root Method and // currently only two levels deep (i.e., one root Method and
// potentially many Method objects pointing to it.) // potentially many Method objects pointing to it.)
private Method root; private Method root;
// This is set by the vm at Method creation
private byte[] typeAnnotations;
// Generics infrastructure // Generics infrastructure
private String getGenericSignature() {return signature;} private String getGenericSignature() {return signature;}
...@@ -152,8 +150,6 @@ public final class Method extends Executable { ...@@ -152,8 +150,6 @@ public final class Method extends Executable {
res.root = this; res.root = this;
// Might as well eagerly propagate this if already present // Might as well eagerly propagate this if already present
res.methodAccessor = methodAccessor; res.methodAccessor = methodAccessor;
res.typeAnnotations = typeAnnotations;
return res; return res;
} }
...@@ -166,10 +162,6 @@ public final class Method extends Executable { ...@@ -166,10 +162,6 @@ public final class Method extends Executable {
byte[] getAnnotationBytes() { byte[] getAnnotationBytes() {
return annotations; return annotations;
} }
@Override
byte[] getTypeAnnotationBytes() {
return typeAnnotations;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
......
...@@ -472,6 +472,11 @@ JVM_GetClassAnnotations(JNIEnv *env, jclass cls); ...@@ -472,6 +472,11 @@ JVM_GetClassAnnotations(JNIEnv *env, jclass cls);
JNIEXPORT jbyteArray JNICALL JNIEXPORT jbyteArray JNICALL
JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls); JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls);
JNIEXPORT jbyteArray JNICALL
JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field);
JNIEXPORT jbyteArray JNICALL
JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method);
/* /*
* New (JDK 1.4) reflection implementation * New (JDK 1.4) reflection implementation
......
...@@ -23,11 +23,7 @@ ...@@ -23,11 +23,7 @@
* questions. * questions.
*/ */
#include <string.h>
#include <stdlib.h>
#include "jni.h" #include "jni.h"
#include "jni_util.h"
#include "jvm.h" #include "jvm.h"
#include "java_lang_reflect_Executable.h" #include "java_lang_reflect_Executable.h"
...@@ -36,3 +32,9 @@ Java_java_lang_reflect_Executable_getParameters0(JNIEnv *env, ...@@ -36,3 +32,9 @@ Java_java_lang_reflect_Executable_getParameters0(JNIEnv *env,
jobject method) { jobject method) {
return JVM_GetMethodParameters(env, method); return JVM_GetMethodParameters(env, method);
} }
JNIEXPORT jbyteArray JNICALL
Java_java_lang_reflect_Executable_getTypeAnnotationBytes0(JNIEnv *env,
jobject method) {
return JVM_GetMethodTypeAnnotations(env, method);
}
/*
* Copyright (c) 2013, 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.
*/
#include "jni.h"
#include "jvm.h"
#include "java_lang_reflect_Field.h"
JNIEXPORT jbyteArray JNICALL
Java_java_lang_reflect_Field_getTypeAnnotationBytes0(JNIEnv *env,
jobject field) {
return JVM_GetFieldTypeAnnotations(env, field);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册