src/share/classes/java/lang/invoke/MemberName.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
jdk Cdiff src/share/classes/java/lang/invoke/MemberName.java
src/share/classes/java/lang/invoke/MemberName.java
Print this page
*** 96,106 ****
* For a constructor, it is always {@code "<init>"}.
*/
public String getName() {
if (name == null) {
expandFromVM();
! if (name == null) return null;
}
return name;
}
public MethodType getMethodOrFieldType() {
--- 96,108 ----
* For a constructor, it is always {@code "<init>"}.
*/
public String getName() {
if (name == null) {
expandFromVM();
! if (name == null) {
! return null;
! }
}
return name;
}
public MethodType getMethodOrFieldType() {
*** 117,148 ****
* must be a method or constructor.
*/
public MethodType getMethodType() {
if (type == null) {
expandFromVM();
! if (type == null) return null;
}
! if (!isInvocable())
throw newIllegalArgumentException("not invocable, no method type");
- if (type instanceof MethodType) {
- return (MethodType) type;
}
if (type instanceof String) {
String sig = (String) type;
MethodType res = MethodType.fromMethodDescriptorString(sig, getClassLoader());
! this.type = res;
! return res;
! }
! if (type instanceof Object[]) {
Object[] typeInfo = (Object[]) type;
Class<?>[] ptypes = (Class<?>[]) typeInfo[1];
Class<?> rtype = (Class<?>) typeInfo[0];
MethodType res = MethodType.methodType(rtype, ptypes);
! this.type = res;
! return res;
}
! throw new InternalError("bad method type "+type);
}
/** Return the actual type under which this method or constructor must be invoked.
* For non-static methods or constructors, this is the type with a leading parameter,
* a reference to declaring class. For static methods, it is the same as the declared type.
--- 119,158 ----
* must be a method or constructor.
*/
public MethodType getMethodType() {
if (type == null) {
expandFromVM();
! if (type == null) {
! return null;
}
! }
! if (!isInvocable()) {
throw newIllegalArgumentException("not invocable, no method type");
}
+
+ final Object typeSnapshot = type;
+ if (typeSnapshot instanceof MethodType) {
+ return (MethodType) typeSnapshot;
+ }
+
+ // type is not a MethodType yet. Convert it thread-safely.
+ synchronized (this) {
if (type instanceof String) {
String sig = (String) type;
MethodType res = MethodType.fromMethodDescriptorString(sig, getClassLoader());
! type = res;
! } else if (type instanceof Object[]) {
Object[] typeInfo = (Object[]) type;
Class<?>[] ptypes = (Class<?>[]) typeInfo[1];
Class<?> rtype = (Class<?>) typeInfo[0];
MethodType res = MethodType.methodType(rtype, ptypes);
! type = res;
}
! // Make sure type is a MethodType for racing threads.
! assert type instanceof MethodType : "bad method type " + type;
! }
! return (MethodType) type;
}
/** Return the actual type under which this method or constructor must be invoked.
* For non-static methods or constructors, this is the type with a leading parameter,
* a reference to declaring class. For static methods, it is the same as the declared type.
*** 171,195 ****
* If it is a type member, that type itself is returned.
*/
public Class<?> getFieldType() {
if (type == null) {
expandFromVM();
! if (type == null) return null;
}
! if (isInvocable())
throw newIllegalArgumentException("not a field or nested class, no simple type");
- if (type instanceof Class<?>) {
- return (Class<?>) type;
}
if (type instanceof String) {
String sig = (String) type;
MethodType mtype = MethodType.fromMethodDescriptorString("()"+sig, getClassLoader());
Class<?> res = mtype.returnType();
! this.type = res;
! return res;
}
! throw new InternalError("bad field type "+type);
}
/** Utility method to produce either the method type or field type of this member. */
public Object getType() {
return (isInvocable() ? getMethodType() : getFieldType());
--- 181,215 ----
* If it is a type member, that type itself is returned.
*/
public Class<?> getFieldType() {
if (type == null) {
expandFromVM();
! if (type == null) {
! return null;
}
! }
! if (isInvocable()) {
throw newIllegalArgumentException("not a field or nested class, no simple type");
}
+
+ final Object typeSnapshot = type;
+ if (typeSnapshot instanceof Class<?>) {
+ return (Class<?>) typeSnapshot;
+ }
+
+ // type is not a Class yet. Convert it thread-safely.
+ synchronized (this) {
if (type instanceof String) {
String sig = (String) type;
MethodType mtype = MethodType.fromMethodDescriptorString("()"+sig, getClassLoader());
Class<?> res = mtype.returnType();
! type = res;
}
! // Make sure type is a Class for racing threads.
! assert type instanceof Class<?> : "bad field type " + type;
! }
! return (Class<?>) type;
}
/** Utility method to produce either the method type or field type of this member. */
public Object getType() {
return (isInvocable() ? getMethodType() : getFieldType());
*** 199,212 ****
* used within the class file format to describe its type.
*/
public String getSignature() {
if (type == null) {
expandFromVM();
! if (type == null) return null;
}
- if (type instanceof String)
- return (String) type;
if (isInvocable())
return BytecodeDescriptor.unparse(getMethodType());
else
return BytecodeDescriptor.unparse(getFieldType());
}
--- 219,232 ----
* used within the class file format to describe its type.
*/
public String getSignature() {
if (type == null) {
expandFromVM();
! if (type == null) {
! return null;
! }
}
if (isInvocable())
return BytecodeDescriptor.unparse(getMethodType());
else
return BytecodeDescriptor.unparse(getFieldType());
}
*** 461,474 ****
assert(testAnyFlags(ALL_KINDS));
assert(this.resolution == null); // nobody should have touched this yet
//assert(referenceKindIsConsistent()); // do this after resolution
}
private void expandFromVM() {
! if (!isResolved()) return;
! if (type instanceof Object[])
! type = null; // don't saddle JVM w/ typeInfo
MethodHandleNatives.expand(this);
}
// Capturing information from the Core Reflection API:
private static int flagsMods(int flags, int mods, byte refKind) {
--- 481,501 ----
assert(testAnyFlags(ALL_KINDS));
assert(this.resolution == null); // nobody should have touched this yet
//assert(referenceKindIsConsistent()); // do this after resolution
}
+ /**
+ * Calls down to the VM to fill in the fields. This method is
+ * synchronized to avoid racing calls.
+ */
private void expandFromVM() {
! if (type != null) {
! return;
! }
! if (!isResolved()) {
! return;
! }
MethodHandleNatives.expand(this);
}
// Capturing information from the Core Reflection API:
private static int flagsMods(int flags, int mods, byte refKind) {
src/share/classes/java/lang/invoke/MemberName.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File