aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/sun/reflect
diff options
context:
space:
mode:
authorrfield <none@none>2013-11-04 10:12:18 -0800
committerrfield <none@none>2013-11-04 10:12:18 -0800
commit189596b00d66fe87ad7c58b271944807cac66c6e (patch)
tree4f3004adfe1be30aea25fa9af373e91e81970e64 /src/share/classes/sun/reflect
parent7a71e583c3a61356d09275aea97b7b3db369c7b4 (diff)
7194897: JSR 292: Cannot create more than 16 instances of an anonymous class
8027681: Lambda serialization fails once reflection proxy generation kicks in Reviewed-by: ksrini, briangoetz, jfranck Contributed-by: joel.franck@oracle.com, brian.goetz@oracle.com, robert.field@oracle.com
Diffstat (limited to 'src/share/classes/sun/reflect')
-rw-r--r--src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java9
-rw-r--r--src/share/classes/sun/reflect/NativeMethodAccessorImpl.java9
-rw-r--r--src/share/classes/sun/reflect/misc/ReflectUtil.java11
3 files changed, 24 insertions, 5 deletions
diff --git a/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java b/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java
index 4f91ddc44..d56c3caab 100644
--- a/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java
+++ b/src/share/classes/sun/reflect/NativeConstructorAccessorImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -26,6 +26,7 @@
package sun.reflect;
import java.lang.reflect.*;
+import sun.reflect.misc.ReflectUtil;
/** Used only for the first few invocations of a Constructor;
afterward, switches to bytecode-based implementation */
@@ -44,7 +45,11 @@ class NativeConstructorAccessorImpl extends ConstructorAccessorImpl {
IllegalArgumentException,
InvocationTargetException
{
- if (++numInvocations > ReflectionFactory.inflationThreshold()) {
+ // We can't inflate a constructor belonging to a vm-anonymous class
+ // because that kind of class can't be referred to by name, hence can't
+ // be found from the generated bytecode.
+ if (++numInvocations > ReflectionFactory.inflationThreshold()
+ && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
ConstructorAccessorImpl acc = (ConstructorAccessorImpl)
new MethodAccessorGenerator().
generateConstructor(c.getDeclaringClass(),
diff --git a/src/share/classes/sun/reflect/NativeMethodAccessorImpl.java b/src/share/classes/sun/reflect/NativeMethodAccessorImpl.java
index 93f186b7b..b1d39e7c9 100644
--- a/src/share/classes/sun/reflect/NativeMethodAccessorImpl.java
+++ b/src/share/classes/sun/reflect/NativeMethodAccessorImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -26,6 +26,7 @@
package sun.reflect;
import java.lang.reflect.*;
+import sun.reflect.misc.ReflectUtil;
/** Used only for the first few invocations of a Method; afterward,
switches to bytecode-based implementation */
@@ -42,7 +43,11 @@ class NativeMethodAccessorImpl extends MethodAccessorImpl {
public Object invoke(Object obj, Object[] args)
throws IllegalArgumentException, InvocationTargetException
{
- if (++numInvocations > ReflectionFactory.inflationThreshold()) {
+ // We can't inflate methods belonging to vm-anonymous classes because
+ // that kind of class can't be referred to by name, hence can't be
+ // found from the generated bytecode.
+ if (++numInvocations > ReflectionFactory.inflationThreshold()
+ && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
MethodAccessorImpl acc = (MethodAccessorImpl)
new MethodAccessorGenerator().
generateMethod(method.getDeclaringClass(),
diff --git a/src/share/classes/sun/reflect/misc/ReflectUtil.java b/src/share/classes/sun/reflect/misc/ReflectUtil.java
index 1f871e8de..4316d422c 100644
--- a/src/share/classes/sun/reflect/misc/ReflectUtil.java
+++ b/src/share/classes/sun/reflect/misc/ReflectUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -298,4 +298,13 @@ public final class ReflectUtil {
}
return false;
}
+
+ /**
+ * Checks if {@code Class cls} is a VM-anonymous class
+ * as defined by {@link sun.misc.Unsafe#defineAnonymousClass}
+ * (not to be confused with a Java Language anonymous inner class).
+ */
+ public static boolean isVMAnonymousClass(Class<?> cls) {
+ return cls.getSimpleName().contains("/");
+ }
}