8137058: Clear out all non-Critical APIs from sun.reflect
Reviewed-by: alanb, jfranck, mchung
--- a/jdk/make/mapfiles/libjava/mapfile-vers Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/make/mapfiles/libjava/mapfile-vers Fri Apr 15 16:19:15 2016 +0100
@@ -237,32 +237,32 @@
Java_jdk_internal_misc_Signal_findSignal0;
Java_jdk_internal_misc_Signal_handle0;
Java_jdk_internal_misc_Signal_raise0;
- Java_sun_reflect_ConstantPool_getClassAt0;
- Java_sun_reflect_ConstantPool_getClassAtIfLoaded0;
- Java_sun_reflect_ConstantPool_getClassRefIndexAt0;
- Java_sun_reflect_ConstantPool_getDoubleAt0;
- Java_sun_reflect_ConstantPool_getFieldAt0;
- Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0;
- Java_sun_reflect_ConstantPool_getFloatAt0;
- Java_sun_reflect_ConstantPool_getIntAt0;
- Java_sun_reflect_ConstantPool_getLongAt0;
- Java_sun_reflect_ConstantPool_getMemberRefInfoAt0;
- Java_sun_reflect_ConstantPool_getMethodAt0;
- Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0;
- Java_sun_reflect_ConstantPool_getNameAndTypeRefIndexAt0;
- Java_sun_reflect_ConstantPool_getNameAndTypeRefInfoAt0;
- Java_sun_reflect_ConstantPool_getSize0;
- Java_sun_reflect_ConstantPool_getStringAt0;
- Java_sun_reflect_ConstantPool_getTagAt0;
- Java_sun_reflect_ConstantPool_getUTF8At0;
+ Java_jdk_internal_reflect_ConstantPool_getClassAt0;
+ Java_jdk_internal_reflect_ConstantPool_getClassAtIfLoaded0;
+ Java_jdk_internal_reflect_ConstantPool_getClassRefIndexAt0;
+ Java_jdk_internal_reflect_ConstantPool_getDoubleAt0;
+ Java_jdk_internal_reflect_ConstantPool_getFieldAt0;
+ Java_jdk_internal_reflect_ConstantPool_getFieldAtIfLoaded0;
+ Java_jdk_internal_reflect_ConstantPool_getFloatAt0;
+ Java_jdk_internal_reflect_ConstantPool_getIntAt0;
+ Java_jdk_internal_reflect_ConstantPool_getLongAt0;
+ Java_jdk_internal_reflect_ConstantPool_getMemberRefInfoAt0;
+ Java_jdk_internal_reflect_ConstantPool_getMethodAt0;
+ Java_jdk_internal_reflect_ConstantPool_getMethodAtIfLoaded0;
+ Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefIndexAt0;
+ Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefInfoAt0;
+ Java_jdk_internal_reflect_ConstantPool_getSize0;
+ Java_jdk_internal_reflect_ConstantPool_getStringAt0;
+ Java_jdk_internal_reflect_ConstantPool_getTagAt0;
+ Java_jdk_internal_reflect_ConstantPool_getUTF8At0;
Java_java_io_Console_istty;
Java_java_io_Console_encoding;
Java_java_io_Console_echo;
- Java_sun_reflect_NativeConstructorAccessorImpl_newInstance0;
- Java_sun_reflect_NativeMethodAccessorImpl_invoke0;
- Java_sun_reflect_Reflection_getCallerClass__;
- Java_sun_reflect_Reflection_getCallerClass__I;
- Java_sun_reflect_Reflection_getClassAccessFlags;
+ Java_jdk_internal_reflect_NativeConstructorAccessorImpl_newInstance0;
+ Java_jdk_internal_reflect_NativeMethodAccessorImpl_invoke0;
+ Java_jdk_internal_reflect_Reflection_getCallerClass__;
+ Java_jdk_internal_reflect_Reflection_getCallerClass__I;
+ Java_jdk_internal_reflect_Reflection_getClassAccessFlags;
Java_jdk_internal_misc_VM_latestUserDefinedLoader;
Java_jdk_internal_misc_VM_getuid;
Java_jdk_internal_misc_VM_geteuid;
--- a/jdk/src/java.base/share/classes/java/io/ObjectStreamClass.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/io/ObjectStreamClass.java Fri Apr 15 16:19:15 2016 +0100
@@ -49,9 +49,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import jdk.internal.misc.Unsafe;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
-import sun.reflect.ReflectionFactory;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
+import jdk.internal.reflect.ReflectionFactory;
import sun.reflect.misc.ReflectUtil;
import static java.io.ObjectStreamField.*;
--- a/jdk/src/java.base/share/classes/java/io/ObjectStreamField.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/io/ObjectStreamField.java Fri Apr 15 16:19:15 2016 +0100
@@ -26,8 +26,8 @@
package java.io;
import java.lang.reflect.Field;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.reflect.misc.ReflectUtil;
/**
--- a/jdk/src/java.base/share/classes/java/lang/Class.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/Class.java Fri Apr 15 16:19:15 2016 +0100
@@ -66,10 +66,10 @@
import jdk.internal.loader.BuiltinClassLoader;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
-import sun.reflect.CallerSensitive;
-import sun.reflect.ConstantPool;
-import sun.reflect.Reflection;
-import sun.reflect.ReflectionFactory;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.ConstantPool;
+import jdk.internal.reflect.Reflection;
+import jdk.internal.reflect.ReflectionFactory;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.repository.ClassRepository;
@@ -3473,7 +3473,7 @@
if (reflectionFactory == null) {
reflectionFactory =
java.security.AccessController.doPrivileged
- (new sun.reflect.ReflectionFactory.GetReflectionFactoryAction());
+ (new ReflectionFactory.GetReflectionFactoryAction());
}
return reflectionFactory;
}
--- a/jdk/src/java.base/share/classes/java/lang/ClassLoader.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/ClassLoader.java Fri Apr 15 16:19:15 2016 +0100
@@ -60,8 +60,8 @@
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.reflect.misc.ReflectUtil;
import sun.security.util.SecurityConstants;
--- a/jdk/src/java.base/share/classes/java/lang/Package.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/Package.java Fri Apr 15 16:19:15 2016 +0100
@@ -36,8 +36,8 @@
import java.util.Objects;
import jdk.internal.loader.BootLoader;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
--- a/jdk/src/java.base/share/classes/java/lang/Runtime.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/Runtime.java Fri Apr 15 16:19:15 2016 +0100
@@ -27,8 +27,8 @@
import java.io.*;
import java.util.StringTokenizer;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
* Every Java application has a single instance of class
--- a/jdk/src/java.base/share/classes/java/lang/SecurityManager.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/SecurityManager.java Fri Apr 15 16:19:15 2016 +0100
@@ -38,7 +38,7 @@
import java.lang.reflect.*;
import java.net.URL;
-import sun.reflect.CallerSensitive;
+import jdk.internal.reflect.CallerSensitive;
import sun.security.util.SecurityConstants;
/**
--- a/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/StackStreamFactory.java Fri Apr 15 16:19:15 2016 +0100
@@ -25,6 +25,7 @@
package java.lang;
import jdk.internal.misc.VM;
+import jdk.internal.reflect.MethodAccessor;
import java.io.PrintStream;
import java.lang.StackWalker.Option;
@@ -1081,13 +1082,13 @@
}
private static boolean isReflectionFrame(Class<?> c) {
- if (c.getName().startsWith("sun.reflect") &&
- !sun.reflect.MethodAccessor.class.isAssignableFrom(c)) {
- throw new InternalError("Not sun.reflect.MethodAccessor: " + c.toString());
+ if (c.getName().startsWith("jdk.internal.reflect") &&
+ !MethodAccessor.class.isAssignableFrom(c)) {
+ throw new InternalError("Not jdk.internal.reflect.MethodAccessor: " + c.toString());
}
// ## should filter all @Hidden frames?
return c == Method.class ||
- sun.reflect.MethodAccessor.class.isAssignableFrom(c) ||
+ MethodAccessor.class.isAssignableFrom(c) ||
c.getName().startsWith("java.lang.invoke.LambdaForm");
}
--- a/jdk/src/java.base/share/classes/java/lang/StackWalker.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/StackWalker.java Fri Apr 15 16:19:15 2016 +0100
@@ -24,7 +24,7 @@
*/
package java.lang;
-import sun.reflect.CallerSensitive;
+import jdk.internal.reflect.CallerSensitive;
import java.util.*;
import java.util.function.Consumer;
--- a/jdk/src/java.base/share/classes/java/lang/System.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/System.java Fri Apr 15 16:19:15 2016 +0100
@@ -56,8 +56,8 @@
import java.util.ResourceBundle;
import java.util.function.Supplier;
import sun.nio.ch.Interruptible;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.security.util.SecurityConstants;
import sun.reflect.annotation.AnnotationType;
import jdk.internal.HotSpotIntrinsicCandidate;
@@ -1978,7 +1978,7 @@
private static void setJavaLangAccess() {
// Allow privileged classes outside of java.lang
SharedSecrets.setJavaLangAccess(new JavaLangAccess(){
- public sun.reflect.ConstantPool getConstantPool(Class<?> klass) {
+ public jdk.internal.reflect.ConstantPool getConstantPool(Class<?> klass) {
return klass.getConstantPool();
}
public boolean casAnnotationType(Class<?> klass, AnnotationType oldType, AnnotationType newType) {
--- a/jdk/src/java.base/share/classes/java/lang/Thread.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/Thread.java Fri Apr 15 16:19:15 2016 +0100
@@ -37,8 +37,8 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.LockSupport;
import sun.nio.ch.Interruptible;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.security.util.SecurityConstants;
import jdk.internal.HotSpotIntrinsicCandidate;
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -33,13 +33,13 @@
import java.util.List;
import java.util.function.Function;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import jdk.internal.vm.annotation.Stable;
import sun.invoke.empty.Empty;
import sun.invoke.util.ValueConversions;
import sun.invoke.util.VerifyType;
import sun.invoke.util.Wrapper;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
import static java.lang.invoke.LambdaForm.*;
import static java.lang.invoke.MethodHandleStatics.*;
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java Fri Apr 15 16:19:15 2016 +0100
@@ -30,8 +30,8 @@
import java.security.PrivilegedAction;
import sun.invoke.WrapperInstance;
import java.util.ArrayList;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.reflect.misc.ReflectUtil;
import static java.lang.invoke.MethodHandleStatics.*;
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Fri Apr 15 16:19:15 2016 +0100
@@ -37,8 +37,8 @@
import sun.invoke.util.ValueConversions;
import sun.invoke.util.VerifyAccess;
import sun.invoke.util.Wrapper;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.reflect.misc.ReflectUtil;
import sun.security.util.SecurityConstants;
import java.lang.invoke.LambdaForm.BasicType;
--- a/jdk/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java Fri Apr 15 16:19:15 2016 +0100
@@ -27,9 +27,9 @@
import java.security.AccessController;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
-import sun.reflect.ReflectionFactory;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
+import jdk.internal.reflect.ReflectionFactory;
import java.lang.annotation.Annotation;
/**
@@ -230,7 +230,7 @@
// very early in the bootstrapping process.
static final ReflectionFactory reflectionFactory =
AccessController.doPrivileged(
- new sun.reflect.ReflectionFactory.GetReflectionFactoryAction());
+ new ReflectionFactory.GetReflectionFactoryAction());
/**
* @throws NullPointerException {@inheritDoc}
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java Fri Apr 15 16:19:15 2016 +0100
@@ -26,9 +26,9 @@
package java.lang.reflect;
import jdk.internal.misc.SharedSecrets;
-import sun.reflect.CallerSensitive;
-import sun.reflect.ConstructorAccessor;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.ConstructorAccessor;
+import jdk.internal.reflect.Reflection;
import sun.reflect.annotation.TypeAnnotation;
import sun.reflect.annotation.TypeAnnotationParser;
import sun.reflect.generics.repository.ConstructorRepository;
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Field.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Field.java Fri Apr 15 16:19:15 2016 +0100
@@ -26,9 +26,9 @@
package java.lang.reflect;
import jdk.internal.misc.SharedSecrets;
-import sun.reflect.CallerSensitive;
-import sun.reflect.FieldAccessor;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.FieldAccessor;
+import jdk.internal.reflect.Reflection;
import sun.reflect.generics.repository.FieldRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Method.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Method.java Fri Apr 15 16:19:15 2016 +0100
@@ -27,9 +27,9 @@
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.SharedSecrets;
-import sun.reflect.CallerSensitive;
-import sun.reflect.MethodAccessor;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.MethodAccessor;
+import jdk.internal.reflect.Reflection;
import sun.reflect.generics.repository.MethodRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Modifier.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Modifier.java Fri Apr 15 16:19:15 2016 +0100
@@ -27,8 +27,8 @@
import java.security.AccessController;
import java.util.StringJoiner;
-import sun.reflect.LangReflectAccess;
-import sun.reflect.ReflectionFactory;
+import jdk.internal.reflect.LangReflectAccess;
+import jdk.internal.reflect.ReflectionFactory;
/**
* The Modifier class provides {@code static} methods and
@@ -51,8 +51,7 @@
* packages
*/
static {
- sun.reflect.ReflectionFactory factory =
- AccessController.doPrivileged(
+ ReflectionFactory factory = AccessController.doPrivileged(
new ReflectionFactory.GetReflectionFactoryAction());
factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
}
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Module.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Module.java Fri Apr 15 16:19:15 2016 +0100
@@ -56,8 +56,8 @@
import jdk.internal.misc.JavaLangReflectModuleAccess;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.module.ServicesCatalog;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.security.util.SecurityConstants;
/**
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java Fri Apr 15 16:19:15 2016 +0100
@@ -47,8 +47,8 @@
import jdk.internal.module.Modules;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.reflect.misc.ReflectUtil;
import sun.security.util.SecurityConstants;
--- a/jdk/src/java.base/share/classes/java/lang/reflect/ReflectAccess.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/ReflectAccess.java Fri Apr 15 16:19:15 2016 +0100
@@ -25,14 +25,14 @@
package java.lang.reflect;
-import sun.reflect.MethodAccessor;
-import sun.reflect.ConstructorAccessor;
+import jdk.internal.reflect.MethodAccessor;
+import jdk.internal.reflect.ConstructorAccessor;
/** Package-private class implementing the
sun.reflect.LangReflectAccess interface, allowing the java.lang
package to instantiate objects in this package. */
-class ReflectAccess implements sun.reflect.LangReflectAccess {
+class ReflectAccess implements jdk.internal.reflect.LangReflectAccess {
public Field newField(Class<?> declaringClass,
String name,
Class<?> type,
--- a/jdk/src/java.base/share/classes/java/net/InetAddress.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/net/InetAddress.java Fri Apr 15 16:19:15 2016 +0100
@@ -894,19 +894,17 @@
*/
private static final class PlatformNameService implements NameService {
- public InetAddress[] lookupAllHostAddr(String host)
- throws UnknownHostException {
-
- return impl.lookupAllHostAddr(host);
-
- }
-
- public String getHostByAddr(byte[] addr) throws UnknownHostException {
-
- return impl.getHostByAddr(addr);
-
+ public InetAddress[] lookupAllHostAddr(String host)
+ throws UnknownHostException
+ {
+ return impl.lookupAllHostAddr(host);
}
+ public String getHostByAddr(byte[] addr)
+ throws UnknownHostException
+ {
+ return impl.getHostByAddr(addr);
+ }
}
/**
@@ -991,7 +989,6 @@
return host;
}
-
/**
* <p>Lookup a host mapping by name. Retrieve the IP addresses
* associated with a host.
@@ -1004,7 +1001,6 @@
* @throws UnknownHostException
* if no IP address for the {@code host} could be found
*/
-
public InetAddress[] lookupAllHostAddr(String host)
throws UnknownHostException {
String hostEntry;
--- a/jdk/src/java.base/share/classes/java/security/AccessController.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/security/AccessController.java Fri Apr 15 16:19:15 2016 +0100
@@ -26,8 +26,8 @@
package java.security;
import sun.security.util.Debug;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
* <p> The AccessController class is used for access control operations
--- a/jdk/src/java.base/share/classes/java/util/ResourceBundle.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/util/ResourceBundle.java Fri Apr 15 16:19:15 2016 +0100
@@ -64,8 +64,8 @@
import jdk.internal.misc.JavaUtilResourceBundleAccess;
import jdk.internal.misc.SharedSecrets;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.util.locale.BaseLocale;
import sun.util.locale.LocaleObjectCache;
import sun.util.locale.provider.ResourceBundleProviderSupport;
--- a/jdk/src/java.base/share/classes/java/util/ServiceLoader.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/util/ServiceLoader.java Fri Apr 15 16:19:15 2016 +0100
@@ -51,8 +51,8 @@
import jdk.internal.module.ServicesCatalog;
import jdk.internal.module.ServicesCatalog.ServiceProvider;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
--- a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java Fri Apr 15 16:19:15 2016 +0100
@@ -42,8 +42,8 @@
import java.security.PrivilegedExceptionAction;
import java.util.function.IntBinaryOperator;
import java.util.function.IntUnaryOperator;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
* A reflection-based utility that enables atomic updates to
--- a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java Fri Apr 15 16:19:15 2016 +0100
@@ -42,8 +42,8 @@
import java.security.PrivilegedExceptionAction;
import java.util.function.LongBinaryOperator;
import java.util.function.LongUnaryOperator;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
* A reflection-based utility that enables atomic updates to
--- a/jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java Fri Apr 15 16:19:15 2016 +0100
@@ -42,8 +42,8 @@
import java.security.PrivilegedExceptionAction;
import java.util.function.BinaryOperator;
import java.util.function.UnaryOperator;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
* A reflection-based utility that enables atomic updates to
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/JavaLangAccess.java Fri Apr 15 16:19:15 2016 +0100
@@ -37,7 +37,7 @@
import java.util.stream.Stream;
import jdk.internal.module.ServicesCatalog;
-import sun.reflect.ConstantPool;
+import jdk.internal.reflect.ConstantPool;
import sun.reflect.annotation.AnnotationType;
import sun.nio.ch.Interruptible;
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java Fri Apr 15 16:19:15 2016 +0100
@@ -28,8 +28,8 @@
import java.lang.reflect.Field;
import java.security.ProtectionDomain;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import jdk.internal.misc.VM;
import jdk.internal.HotSpotIntrinsicCandidate;
@@ -58,7 +58,7 @@
private static native void registerNatives();
static {
registerNatives();
- sun.reflect.Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
+ Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
}
private Unsafe() {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/AccessorGenerator.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,723 @@
+/*
+ * 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
+ * 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.*;
+import jdk.internal.misc.Unsafe;
+
+/** Shared functionality for all accessor generators */
+
+class AccessorGenerator implements ClassFileConstants {
+ static final Unsafe unsafe = Unsafe.getUnsafe();
+
+ // Constants because there's no way to say "short integer constant",
+ // i.e., "1S"
+ protected static final short S0 = (short) 0;
+ protected static final short S1 = (short) 1;
+ protected static final short S2 = (short) 2;
+ protected static final short S3 = (short) 3;
+ protected static final short S4 = (short) 4;
+ protected static final short S5 = (short) 5;
+ protected static final short S6 = (short) 6;
+
+ // Instance variables for shared functionality between
+ // FieldAccessorGenerator and MethodAccessorGenerator
+ protected ClassFileAssembler asm;
+ protected int modifiers;
+ protected short thisClass;
+ protected short superClass;
+ protected short targetClass;
+ // Common constant pool entries to FieldAccessor and MethodAccessor
+ protected short throwableClass;
+ protected short classCastClass;
+ protected short nullPointerClass;
+ protected short illegalArgumentClass;
+ protected short invocationTargetClass;
+ protected short initIdx;
+ protected short initNameAndTypeIdx;
+ protected short initStringNameAndTypeIdx;
+ protected short nullPointerCtorIdx;
+ protected short illegalArgumentCtorIdx;
+ protected short illegalArgumentStringCtorIdx;
+ protected short invocationTargetCtorIdx;
+ protected short superCtorIdx;
+ protected short objectClass;
+ protected short toStringIdx;
+ protected short codeIdx;
+ protected short exceptionsIdx;
+ // Boxing
+ protected short valueOfIdx;
+ protected short booleanIdx;
+ protected short booleanBoxIdx;
+ protected short booleanUnboxIdx;
+ protected short byteIdx;
+ protected short byteBoxIdx;
+ protected short byteUnboxIdx;
+ protected short characterIdx;
+ protected short characterBoxIdx;
+ protected short characterUnboxIdx;
+ protected short doubleIdx;
+ protected short doubleBoxIdx;
+ protected short doubleUnboxIdx;
+ protected short floatIdx;
+ protected short floatBoxIdx;
+ protected short floatUnboxIdx;
+ protected short integerIdx;
+ protected short integerBoxIdx;
+ protected short integerUnboxIdx;
+ protected short longIdx;
+ protected short longBoxIdx;
+ protected short longUnboxIdx;
+ protected short shortIdx;
+ protected short shortBoxIdx;
+ protected short shortUnboxIdx;
+
+ protected final short NUM_COMMON_CPOOL_ENTRIES = (short) 30;
+ protected final short NUM_BOXING_CPOOL_ENTRIES = (short) 73;
+
+ // Requires that superClass has been set up
+ protected void emitCommonConstantPoolEntries() {
+ // + [UTF-8] "java/lang/Throwable"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/ClassCastException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/NullPointerException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/IllegalArgumentException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/InvocationTargetException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "<init>"
+ // + [UTF-8] "()V"
+ // + [CONSTANT_NameAndType_info] for above
+ // + [CONSTANT_Methodref_info] for NullPointerException's constructor
+ // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor
+ // + [UTF-8] "(Ljava/lang/String;)V"
+ // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/String;)V"
+ // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor taking a String
+ // + [UTF-8] "(Ljava/lang/Throwable;)V"
+ // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/Throwable;)V"
+ // + [CONSTANT_Methodref_info] for InvocationTargetException's constructor
+ // + [CONSTANT_Methodref_info] for "super()"
+ // + [UTF-8] "java/lang/Object"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "toString"
+ // + [UTF-8] "()Ljava/lang/String;"
+ // + [CONSTANT_NameAndType_info] for "toString()Ljava/lang/String;"
+ // + [CONSTANT_Methodref_info] for Object's toString method
+ // + [UTF-8] "Code"
+ // + [UTF-8] "Exceptions"
+ asm.emitConstantPoolUTF8("java/lang/Throwable");
+ asm.emitConstantPoolClass(asm.cpi());
+ throwableClass = asm.cpi();
+ asm.emitConstantPoolUTF8("java/lang/ClassCastException");
+ asm.emitConstantPoolClass(asm.cpi());
+ classCastClass = asm.cpi();
+ asm.emitConstantPoolUTF8("java/lang/NullPointerException");
+ asm.emitConstantPoolClass(asm.cpi());
+ nullPointerClass = asm.cpi();
+ asm.emitConstantPoolUTF8("java/lang/IllegalArgumentException");
+ asm.emitConstantPoolClass(asm.cpi());
+ illegalArgumentClass = asm.cpi();
+ asm.emitConstantPoolUTF8("java/lang/reflect/InvocationTargetException");
+ asm.emitConstantPoolClass(asm.cpi());
+ invocationTargetClass = asm.cpi();
+ asm.emitConstantPoolUTF8("<init>");
+ initIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("()V");
+ asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
+ initNameAndTypeIdx = asm.cpi();
+ asm.emitConstantPoolMethodref(nullPointerClass, initNameAndTypeIdx);
+ nullPointerCtorIdx = asm.cpi();
+ asm.emitConstantPoolMethodref(illegalArgumentClass, initNameAndTypeIdx);
+ illegalArgumentCtorIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(Ljava/lang/String;)V");
+ asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
+ initStringNameAndTypeIdx = asm.cpi();
+ asm.emitConstantPoolMethodref(illegalArgumentClass, initStringNameAndTypeIdx);
+ illegalArgumentStringCtorIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(Ljava/lang/Throwable;)V");
+ asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(invocationTargetClass, asm.cpi());
+ invocationTargetCtorIdx = asm.cpi();
+ asm.emitConstantPoolMethodref(superClass, initNameAndTypeIdx);
+ superCtorIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("java/lang/Object");
+ asm.emitConstantPoolClass(asm.cpi());
+ objectClass = asm.cpi();
+ asm.emitConstantPoolUTF8("toString");
+ asm.emitConstantPoolUTF8("()Ljava/lang/String;");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(objectClass, asm.cpi());
+ toStringIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("Code");
+ codeIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("Exceptions");
+ exceptionsIdx = asm.cpi();
+ }
+
+ /** Constant pool entries required to be able to box/unbox primitive
+ types. Note that we don't emit these if we don't need them. */
+ protected void emitBoxingContantPoolEntries() {
+ // * [UTF-8] "valueOf"
+ // * [UTF-8] "java/lang/Boolean"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(Z)Ljava/lang/Boolean;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "booleanValue"
+ // * [UTF-8] "()Z"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Byte"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(B)Ljava/lang/Byte;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "byteValue"
+ // * [UTF-8] "()B"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Character"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(C)Ljava/lang/Character;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "charValue"
+ // * [UTF-8] "()C"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Double"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(D)Ljava/lang/Double;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "doubleValue"
+ // * [UTF-8] "()D"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Float"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(F)Ljava/lang/Float;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "floatValue"
+ // * [UTF-8] "()F"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Integer"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(I)Ljava/lang/Integer;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "intValue"
+ // * [UTF-8] "()I"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Long"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(J)Ljava/lang/Long;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "longValue"
+ // * [UTF-8] "()J"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Short"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(S)Ljava/lang/Short;"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "shortValue"
+ // * [UTF-8] "()S"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+
+ // valueOf-method name
+ asm.emitConstantPoolUTF8("valueOf");
+ valueOfIdx = asm.cpi();
+
+ // Boolean
+ asm.emitConstantPoolUTF8("java/lang/Boolean");
+ asm.emitConstantPoolClass(asm.cpi());
+ booleanIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(Z)Ljava/lang/Boolean;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ booleanBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("booleanValue");
+ asm.emitConstantPoolUTF8("()Z");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ booleanUnboxIdx = asm.cpi();
+
+ // Byte
+ asm.emitConstantPoolUTF8("java/lang/Byte");
+ asm.emitConstantPoolClass(asm.cpi());
+ byteIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(B)Ljava/lang/Byte;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ byteBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("byteValue");
+ asm.emitConstantPoolUTF8("()B");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ byteUnboxIdx = asm.cpi();
+
+ // Character
+ asm.emitConstantPoolUTF8("java/lang/Character");
+ asm.emitConstantPoolClass(asm.cpi());
+ characterIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(C)Ljava/lang/Character;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ characterBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("charValue");
+ asm.emitConstantPoolUTF8("()C");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ characterUnboxIdx = asm.cpi();
+
+ // Double
+ asm.emitConstantPoolUTF8("java/lang/Double");
+ asm.emitConstantPoolClass(asm.cpi());
+ doubleIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(D)Ljava/lang/Double;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ doubleBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("doubleValue");
+ asm.emitConstantPoolUTF8("()D");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ doubleUnboxIdx = asm.cpi();
+
+ // Float
+ asm.emitConstantPoolUTF8("java/lang/Float");
+ asm.emitConstantPoolClass(asm.cpi());
+ floatIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(F)Ljava/lang/Float;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ floatBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("floatValue");
+ asm.emitConstantPoolUTF8("()F");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ floatUnboxIdx = asm.cpi();
+
+ // Integer
+ asm.emitConstantPoolUTF8("java/lang/Integer");
+ asm.emitConstantPoolClass(asm.cpi());
+ integerIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(I)Ljava/lang/Integer;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ integerBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("intValue");
+ asm.emitConstantPoolUTF8("()I");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ integerUnboxIdx = asm.cpi();
+
+ // Long
+ asm.emitConstantPoolUTF8("java/lang/Long");
+ asm.emitConstantPoolClass(asm.cpi());
+ longIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(J)Ljava/lang/Long;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ longBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("longValue");
+ asm.emitConstantPoolUTF8("()J");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ longUnboxIdx = asm.cpi();
+
+ // Short
+ asm.emitConstantPoolUTF8("java/lang/Short");
+ asm.emitConstantPoolClass(asm.cpi());
+ shortIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("(S)Ljava/lang/Short;");
+ asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
+ shortBoxIdx = asm.cpi();
+ asm.emitConstantPoolUTF8("shortValue");
+ asm.emitConstantPoolUTF8("()S");
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
+ shortUnboxIdx = asm.cpi();
+ }
+
+ // Necessary because of Java's annoying promotion rules
+ protected static short add(short s1, short s2) {
+ return (short) (s1 + s2);
+ }
+
+ protected static short sub(short s1, short s2) {
+ return (short) (s1 - s2);
+ }
+
+ protected boolean isStatic() {
+ return Modifier.isStatic(modifiers);
+ }
+
+ protected boolean isPrivate() {
+ return Modifier.isPrivate(modifiers);
+ }
+
+ /** Returns class name in "internal" form (i.e., '/' separators
+ instead of '.') */
+ protected static String getClassName
+ (Class<?> c, boolean addPrefixAndSuffixForNonPrimitiveTypes)
+ {
+ if (c.isPrimitive()) {
+ if (c == Boolean.TYPE) {
+ return "Z";
+ } else if (c == Byte.TYPE) {
+ return "B";
+ } else if (c == Character.TYPE) {
+ return "C";
+ } else if (c == Double.TYPE) {
+ return "D";
+ } else if (c == Float.TYPE) {
+ return "F";
+ } else if (c == Integer.TYPE) {
+ return "I";
+ } else if (c == Long.TYPE) {
+ return "J";
+ } else if (c == Short.TYPE) {
+ return "S";
+ } else if (c == Void.TYPE) {
+ return "V";
+ }
+ throw new InternalError("Should have found primitive type");
+ } else if (c.isArray()) {
+ return "[" + getClassName(c.getComponentType(), true);
+ } else {
+ if (addPrefixAndSuffixForNonPrimitiveTypes) {
+ return internalize("L" + c.getName() + ";");
+ } else {
+ return internalize(c.getName());
+ }
+ }
+ }
+
+ private static String internalize(String className) {
+ return className.replace('.', '/');
+ }
+
+ protected void emitConstructor() {
+ // Generate code into fresh code buffer
+ ClassFileAssembler cb = new ClassFileAssembler();
+ // 0 incoming arguments
+ cb.setMaxLocals(1);
+ cb.opc_aload_0();
+ cb.opc_invokespecial(superCtorIdx, 0, 0);
+ cb.opc_return();
+
+ // Emit method
+ emitMethod(initIdx, cb.getMaxLocals(), cb, null, null);
+ }
+
+ // The descriptor's index in the constant pool must be (1 +
+ // nameIdx). "numArgs" must indicate ALL arguments, including the
+ // implicit "this" argument; double and long arguments each count
+ // as 2 in this count. The code buffer must NOT contain the code
+ // length. The exception table may be null, but if non-null must
+ // NOT contain the exception table's length. The checked exception
+ // indices may be null.
+ protected void emitMethod(short nameIdx,
+ int numArgs,
+ ClassFileAssembler code,
+ ClassFileAssembler exceptionTable,
+ short[] checkedExceptionIndices)
+ {
+ int codeLen = code.getLength();
+ int excLen = 0;
+ if (exceptionTable != null) {
+ excLen = exceptionTable.getLength();
+ if ((excLen % 8) != 0) {
+ throw new IllegalArgumentException("Illegal exception table");
+ }
+ }
+ int attrLen = 12 + codeLen + excLen;
+ excLen = excLen / 8; // No-op if no exception table
+
+ asm.emitShort(ACC_PUBLIC);
+ asm.emitShort(nameIdx);
+ asm.emitShort(add(nameIdx, S1));
+ if (checkedExceptionIndices == null) {
+ // Code attribute only
+ asm.emitShort(S1);
+ } else {
+ // Code and Exceptions attributes
+ asm.emitShort(S2);
+ }
+ // Code attribute
+ asm.emitShort(codeIdx);
+ asm.emitInt(attrLen);
+ asm.emitShort(code.getMaxStack());
+ asm.emitShort((short) Math.max(numArgs, code.getMaxLocals()));
+ asm.emitInt(codeLen);
+ asm.append(code);
+ asm.emitShort((short) excLen);
+ if (exceptionTable != null) {
+ asm.append(exceptionTable);
+ }
+ asm.emitShort(S0); // No additional attributes for Code attribute
+ if (checkedExceptionIndices != null) {
+ // Exceptions attribute
+ asm.emitShort(exceptionsIdx);
+ asm.emitInt(2 + 2 * checkedExceptionIndices.length);
+ asm.emitShort((short) checkedExceptionIndices.length);
+ for (int i = 0; i < checkedExceptionIndices.length; i++) {
+ asm.emitShort(checkedExceptionIndices[i]);
+ }
+ }
+ }
+
+ protected short indexForPrimitiveType(Class<?> type) {
+ if (type == Boolean.TYPE) {
+ return booleanIdx;
+ } else if (type == Byte.TYPE) {
+ return byteIdx;
+ } else if (type == Character.TYPE) {
+ return characterIdx;
+ } else if (type == Double.TYPE) {
+ return doubleIdx;
+ } else if (type == Float.TYPE) {
+ return floatIdx;
+ } else if (type == Integer.TYPE) {
+ return integerIdx;
+ } else if (type == Long.TYPE) {
+ return longIdx;
+ } else if (type == Short.TYPE) {
+ return shortIdx;
+ }
+ throw new InternalError("Should have found primitive type");
+ }
+
+ protected short boxingMethodForPrimitiveType(Class<?> type) {
+ if (type == Boolean.TYPE) {
+ return booleanBoxIdx;
+ } else if (type == Byte.TYPE) {
+ return byteBoxIdx;
+ } else if (type == Character.TYPE) {
+ return characterBoxIdx;
+ } else if (type == Double.TYPE) {
+ return doubleBoxIdx;
+ } else if (type == Float.TYPE) {
+ return floatBoxIdx;
+ } else if (type == Integer.TYPE) {
+ return integerBoxIdx;
+ } else if (type == Long.TYPE) {
+ return longBoxIdx;
+ } else if (type == Short.TYPE) {
+ return shortBoxIdx;
+ }
+ throw new InternalError("Should have found primitive type");
+ }
+
+ /** Returns true for widening or identity conversions for primitive
+ types only */
+ protected static boolean canWidenTo(Class<?> type, Class<?> otherType) {
+ if (!type.isPrimitive()) {
+ return false;
+ }
+
+ // Widening conversions (from JVM spec):
+ // byte to short, int, long, float, or double
+ // short to int, long, float, or double
+ // char to int, long, float, or double
+ // int to long, float, or double
+ // long to float or double
+ // float to double
+
+ if (type == Boolean.TYPE) {
+ if (otherType == Boolean.TYPE) {
+ return true;
+ }
+ } else if (type == Byte.TYPE) {
+ if ( otherType == Byte.TYPE
+ || otherType == Short.TYPE
+ || otherType == Integer.TYPE
+ || otherType == Long.TYPE
+ || otherType == Float.TYPE
+ || otherType == Double.TYPE) {
+ return true;
+ }
+ } else if (type == Short.TYPE) {
+ if ( otherType == Short.TYPE
+ || otherType == Integer.TYPE
+ || otherType == Long.TYPE
+ || otherType == Float.TYPE
+ || otherType == Double.TYPE) {
+ return true;
+ }
+ } else if (type == Character.TYPE) {
+ if ( otherType == Character.TYPE
+ || otherType == Integer.TYPE
+ || otherType == Long.TYPE
+ || otherType == Float.TYPE
+ || otherType == Double.TYPE) {
+ return true;
+ }
+ } else if (type == Integer.TYPE) {
+ if ( otherType == Integer.TYPE
+ || otherType == Long.TYPE
+ || otherType == Float.TYPE
+ || otherType == Double.TYPE) {
+ return true;
+ }
+ } else if (type == Long.TYPE) {
+ if ( otherType == Long.TYPE
+ || otherType == Float.TYPE
+ || otherType == Double.TYPE) {
+ return true;
+ }
+ } else if (type == Float.TYPE) {
+ if ( otherType == Float.TYPE
+ || otherType == Double.TYPE) {
+ return true;
+ }
+ } else if (type == Double.TYPE) {
+ if (otherType == Double.TYPE) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /** Emits the widening bytecode for the given primitive conversion
+ (or none if the identity conversion). Requires that a primitive
+ conversion exists; i.e., canWidenTo must have already been
+ called and returned true. */
+ protected static void emitWideningBytecodeForPrimitiveConversion
+ (ClassFileAssembler cb,
+ Class<?> fromType,
+ Class<?> toType)
+ {
+ // Note that widening conversions for integral types (i.e., "b2s",
+ // "s2i") are no-ops since values on the Java stack are
+ // sign-extended.
+
+ // Widening conversions (from JVM spec):
+ // byte to short, int, long, float, or double
+ // short to int, long, float, or double
+ // char to int, long, float, or double
+ // int to long, float, or double
+ // long to float or double
+ // float to double
+
+ if ( fromType == Byte.TYPE
+ || fromType == Short.TYPE
+ || fromType == Character.TYPE
+ || fromType == Integer.TYPE) {
+ if (toType == Long.TYPE) {
+ cb.opc_i2l();
+ } else if (toType == Float.TYPE) {
+ cb.opc_i2f();
+ } else if (toType == Double.TYPE) {
+ cb.opc_i2d();
+ }
+ } else if (fromType == Long.TYPE) {
+ if (toType == Float.TYPE) {
+ cb.opc_l2f();
+ } else if (toType == Double.TYPE) {
+ cb.opc_l2d();
+ }
+ } else if (fromType == Float.TYPE) {
+ if (toType == Double.TYPE) {
+ cb.opc_f2d();
+ }
+ }
+
+ // Otherwise, was identity or no-op conversion. Fall through.
+ }
+
+ protected short unboxingMethodForPrimitiveType(Class<?> primType) {
+ if (primType == Boolean.TYPE) {
+ return booleanUnboxIdx;
+ } else if (primType == Byte.TYPE) {
+ return byteUnboxIdx;
+ } else if (primType == Character.TYPE) {
+ return characterUnboxIdx;
+ } else if (primType == Short.TYPE) {
+ return shortUnboxIdx;
+ } else if (primType == Integer.TYPE) {
+ return integerUnboxIdx;
+ } else if (primType == Long.TYPE) {
+ return longUnboxIdx;
+ } else if (primType == Float.TYPE) {
+ return floatUnboxIdx;
+ } else if (primType == Double.TYPE) {
+ return doubleUnboxIdx;
+ }
+ throw new InternalError("Illegal primitive type " + primType.getName());
+ }
+
+ protected static final Class<?>[] primitiveTypes = new Class<?>[] {
+ Boolean.TYPE,
+ Byte.TYPE,
+ Character.TYPE,
+ Short.TYPE,
+ Integer.TYPE,
+ Long.TYPE,
+ Float.TYPE,
+ Double.TYPE
+ };
+
+ /** We don't consider "Void" to be a primitive type */
+ protected static boolean isPrimitive(Class<?> c) {
+ return (c.isPrimitive() && c != Void.TYPE);
+ }
+
+ protected int typeSizeInStackSlots(Class<?> c) {
+ if (c == Void.TYPE) {
+ return 0;
+ }
+ if (c == Long.TYPE || c == Double.TYPE) {
+ return 2;
+ }
+ return 1;
+ }
+
+ private ClassFileAssembler illegalArgumentCodeBuffer;
+ protected ClassFileAssembler illegalArgumentCodeBuffer() {
+ if (illegalArgumentCodeBuffer == null) {
+ illegalArgumentCodeBuffer = new ClassFileAssembler();
+ illegalArgumentCodeBuffer.opc_new(illegalArgumentClass);
+ illegalArgumentCodeBuffer.opc_dup();
+ illegalArgumentCodeBuffer.opc_invokespecial(illegalArgumentCtorIdx, 0, 0);
+ illegalArgumentCodeBuffer.opc_athrow();
+ }
+
+ return illegalArgumentCodeBuffer;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/BootstrapConstructorAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2001, 2011, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Constructor;
+
+/** Uses Unsafe.allocateObject() to instantiate classes; only used for
+ bootstrapping. */
+
+class BootstrapConstructorAccessorImpl extends ConstructorAccessorImpl {
+ private final Constructor<?> constructor;
+
+ BootstrapConstructorAccessorImpl(Constructor<?> c) {
+ this.constructor = c;
+ }
+
+ public Object newInstance(Object[] args)
+ throws IllegalArgumentException, InvocationTargetException
+ {
+ try {
+ return UnsafeFieldAccessorImpl.unsafe.
+ allocateInstance(constructor.getDeclaringClass());
+ } catch (InstantiationException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ByteVector.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** A growable array of bytes. */
+
+interface ByteVector {
+ public int getLength();
+ public byte get(int index);
+ public void put(int index, byte value);
+ public void add(byte value);
+ public void trim();
+ public byte[] getData();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ByteVectorFactory.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+class ByteVectorFactory {
+ static ByteVector create() {
+ return new ByteVectorImpl();
+ }
+
+ static ByteVector create(int sz) {
+ return new ByteVectorImpl(sz);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ByteVectorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+class ByteVectorImpl implements ByteVector {
+ private byte[] data;
+ private int pos;
+
+ public ByteVectorImpl() {
+ this(100);
+ }
+
+ public ByteVectorImpl(int sz) {
+ data = new byte[sz];
+ pos = -1;
+ }
+
+ public int getLength() {
+ return pos + 1;
+ }
+
+ public byte get(int index) {
+ if (index >= data.length) {
+ resize(index);
+ pos = index;
+ }
+ return data[index];
+ }
+
+ public void put(int index, byte value) {
+ if (index >= data.length) {
+ resize(index);
+ pos = index;
+ }
+ data[index] = value;
+ }
+
+ public void add(byte value) {
+ if (++pos >= data.length) {
+ resize(pos);
+ }
+ data[pos] = value;
+ }
+
+ public void trim() {
+ if (pos != data.length - 1) {
+ byte[] newData = new byte[pos + 1];
+ System.arraycopy(data, 0, newData, 0, pos + 1);
+ data = newData;
+ }
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ private void resize(int minSize) {
+ if (minSize <= 2 * data.length) {
+ minSize = 2 * data.length;
+ }
+ byte[] newData = new byte[minSize];
+ System.arraycopy(data, 0, newData, 0, data.length);
+ data = newData;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/CallerSensitive.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.annotation.*;
+import static java.lang.annotation.ElementType.*;
+
+/**
+ * A method annotated @CallerSensitive is sensitive to its calling class,
+ * via {@link jdk.internal.reflect.Reflection#getCallerClass Reflection.getCallerClass},
+ * or via some equivalent.
+ *
+ * @author John R. Rose
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({METHOD})
+public @interface CallerSensitive {
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ClassDefiner.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2001, 2011, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import jdk.internal.misc.Unsafe;
+
+/** Utility class which assists in calling Unsafe.defineClass() by
+ creating a new class loader which delegates to the one needed in
+ order for proper resolution of the given bytecodes to occur. */
+
+class ClassDefiner {
+ static final Unsafe unsafe = Unsafe.getUnsafe();
+
+ /** <P> We define generated code into a new class loader which
+ delegates to the defining loader of the target class. It is
+ necessary for the VM to be able to resolve references to the
+ target class from the generated bytecodes, which could not occur
+ if the generated code was loaded into the bootstrap class
+ loader. </P>
+
+ <P> There are two primary reasons for creating a new loader
+ instead of defining these bytecodes directly into the defining
+ loader of the target class: first, it avoids any possible
+ security risk of having these bytecodes in the same loader.
+ Second, it allows the generated bytecodes to be unloaded earlier
+ than would otherwise be possible, decreasing run-time
+ footprint. </P>
+ */
+ static Class<?> defineClass(String name, byte[] bytes, int off, int len,
+ final ClassLoader parentClassLoader)
+ {
+ ClassLoader newLoader = AccessController.doPrivileged(
+ new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return new DelegatingClassLoader(parentClassLoader);
+ }
+ });
+ return unsafe.defineClass(name, bytes, off, len, newLoader, null);
+ }
+}
+
+
+// NOTE: this class's name and presence are known to the virtual
+// machine as of the fix for 4474172.
+class DelegatingClassLoader extends ClassLoader {
+ DelegatingClassLoader(ClassLoader parent) {
+ super(parent);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ClassFileAssembler.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,671 @@
+/*
+ * Copyright (c) 2001, 2004, 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.
+ */
+
+package jdk.internal.reflect;
+
+class ClassFileAssembler implements ClassFileConstants {
+ private ByteVector vec;
+ private short cpIdx = 0;
+
+ public ClassFileAssembler() {
+ this(ByteVectorFactory.create());
+ }
+
+ public ClassFileAssembler(ByteVector vec) {
+ this.vec = vec;
+ }
+
+ public ByteVector getData() {
+ return vec;
+ }
+
+ /** Length in bytes */
+ public short getLength() {
+ return (short) vec.getLength();
+ }
+
+ public void emitMagicAndVersion() {
+ emitInt(0xCAFEBABE);
+ emitShort((short) 0);
+ emitShort((short) 49);
+ }
+
+ public void emitInt(int val) {
+ emitByte((byte) (val >> 24));
+ emitByte((byte) ((val >> 16) & 0xFF));
+ emitByte((byte) ((val >> 8) & 0xFF));
+ emitByte((byte) (val & 0xFF));
+ }
+
+ public void emitShort(short val) {
+ emitByte((byte) ((val >> 8) & 0xFF));
+ emitByte((byte) (val & 0xFF));
+ }
+
+ // Support for labels; package-private
+ void emitShort(short bci, short val) {
+ vec.put(bci, (byte) ((val >> 8) & 0xFF));
+ vec.put(bci + 1, (byte) (val & 0xFF));
+ }
+
+ public void emitByte(byte val) {
+ vec.add(val);
+ }
+
+ public void append(ClassFileAssembler asm) {
+ append(asm.vec);
+ }
+
+ public void append(ByteVector vec) {
+ for (int i = 0; i < vec.getLength(); i++) {
+ emitByte(vec.get(i));
+ }
+ }
+
+ /** Keeps track of the current (one-based) constant pool index;
+ incremented after emitting one of the following constant pool
+ entries. Can fetch the current constant pool index for use in
+ later entries. Index points at the last valid constant pool
+ entry; initially invalid. It is illegal to fetch the constant
+ pool index before emitting at least one constant pool entry. */
+ public short cpi() {
+ if (cpIdx == 0) {
+ throw new RuntimeException("Illegal use of ClassFileAssembler");
+ }
+ return cpIdx;
+ }
+
+ public void emitConstantPoolUTF8(String str) {
+ // NOTE: can not use str.getBytes("UTF-8") here because of
+ // bootstrapping issues with the character set converters.
+ byte[] bytes = UTF8.encode(str);
+ emitByte(CONSTANT_Utf8);
+ emitShort((short) bytes.length);
+ for (int i = 0; i < bytes.length; i++) {
+ emitByte(bytes[i]);
+ }
+ cpIdx++;
+ }
+
+ public void emitConstantPoolClass(short index) {
+ emitByte(CONSTANT_Class);
+ emitShort(index);
+ cpIdx++;
+ }
+
+ public void emitConstantPoolNameAndType(short nameIndex, short typeIndex) {
+ emitByte(CONSTANT_NameAndType);
+ emitShort(nameIndex);
+ emitShort(typeIndex);
+ cpIdx++;
+ }
+
+ public void emitConstantPoolFieldref
+ (short classIndex, short nameAndTypeIndex)
+ {
+ emitByte(CONSTANT_Fieldref);
+ emitShort(classIndex);
+ emitShort(nameAndTypeIndex);
+ cpIdx++;
+ }
+
+ public void emitConstantPoolMethodref
+ (short classIndex, short nameAndTypeIndex)
+ {
+ emitByte(CONSTANT_Methodref);
+ emitShort(classIndex);
+ emitShort(nameAndTypeIndex);
+ cpIdx++;
+ }
+
+ public void emitConstantPoolInterfaceMethodref
+ (short classIndex, short nameAndTypeIndex)
+ {
+ emitByte(CONSTANT_InterfaceMethodref);
+ emitShort(classIndex);
+ emitShort(nameAndTypeIndex);
+ cpIdx++;
+ }
+
+ public void emitConstantPoolString(short utf8Index) {
+ emitByte(CONSTANT_String);
+ emitShort(utf8Index);
+ cpIdx++;
+ }
+
+ //----------------------------------------------------------------------
+ // Opcodes. Keeps track of maximum stack and locals. Make a new
+ // assembler for each piece of assembled code, then append the
+ // result to the previous assembler's class file.
+ //
+
+ private int stack = 0;
+ private int maxStack = 0;
+ private int maxLocals = 0;
+
+ private void incStack() {
+ setStack(stack + 1);
+ }
+
+ private void decStack() {
+ --stack;
+ }
+
+ public short getMaxStack() {
+ return (short) maxStack;
+ }
+
+ public short getMaxLocals() {
+ return (short) maxLocals;
+ }
+
+ /** It's necessary to be able to specify the number of arguments at
+ the beginning of the method (which translates to the initial
+ value of max locals) */
+ public void setMaxLocals(int maxLocals) {
+ this.maxLocals = maxLocals;
+ }
+
+ /** Needed to do flow control. Returns current stack depth. */
+ public int getStack() {
+ return stack;
+ }
+
+ /** Needed to do flow control. */
+ public void setStack(int value) {
+ stack = value;
+ if (stack > maxStack) {
+ maxStack = stack;
+ }
+ }
+
+ ///////////////
+ // Constants //
+ ///////////////
+
+ public void opc_aconst_null() {
+ emitByte(opc_aconst_null);
+ incStack();
+ }
+
+ public void opc_sipush(short constant) {
+ emitByte(opc_sipush);
+ emitShort(constant);
+ incStack();
+ }
+
+ public void opc_ldc(byte cpIdx) {
+ emitByte(opc_ldc);
+ emitByte(cpIdx);
+ incStack();
+ }
+
+ /////////////////////////////////////
+ // Local variable loads and stores //
+ /////////////////////////////////////
+
+ public void opc_iload_0() {
+ emitByte(opc_iload_0);
+ if (maxLocals < 1) maxLocals = 1;
+ incStack();
+ }
+
+ public void opc_iload_1() {
+ emitByte(opc_iload_1);
+ if (maxLocals < 2) maxLocals = 2;
+ incStack();
+ }
+
+ public void opc_iload_2() {
+ emitByte(opc_iload_2);
+ if (maxLocals < 3) maxLocals = 3;
+ incStack();
+ }
+
+ public void opc_iload_3() {
+ emitByte(opc_iload_3);
+ if (maxLocals < 4) maxLocals = 4;
+ incStack();
+ }
+
+ public void opc_lload_0() {
+ emitByte(opc_lload_0);
+ if (maxLocals < 2) maxLocals = 2;
+ incStack();
+ incStack();
+ }
+
+ public void opc_lload_1() {
+ emitByte(opc_lload_1);
+ if (maxLocals < 3) maxLocals = 3;
+ incStack();
+ incStack();
+ }
+
+ public void opc_lload_2() {
+ emitByte(opc_lload_2);
+ if (maxLocals < 4) maxLocals = 4;
+ incStack();
+ incStack();
+ }
+
+ public void opc_lload_3() {
+ emitByte(opc_lload_3);
+ if (maxLocals < 5) maxLocals = 5;
+ incStack();
+ incStack();
+ }
+
+ public void opc_fload_0() {
+ emitByte(opc_fload_0);
+ if (maxLocals < 1) maxLocals = 1;
+ incStack();
+ }
+
+ public void opc_fload_1() {
+ emitByte(opc_fload_1);
+ if (maxLocals < 2) maxLocals = 2;
+ incStack();
+ }
+
+ public void opc_fload_2() {
+ emitByte(opc_fload_2);
+ if (maxLocals < 3) maxLocals = 3;
+ incStack();
+ }
+
+ public void opc_fload_3() {
+ emitByte(opc_fload_3);
+ if (maxLocals < 4) maxLocals = 4;
+ incStack();
+ }
+
+ public void opc_dload_0() {
+ emitByte(opc_dload_0);
+ if (maxLocals < 2) maxLocals = 2;
+ incStack();
+ incStack();
+ }
+
+ public void opc_dload_1() {
+ emitByte(opc_dload_1);
+ if (maxLocals < 3) maxLocals = 3;
+ incStack();
+ incStack();
+ }
+
+ public void opc_dload_2() {
+ emitByte(opc_dload_2);
+ if (maxLocals < 4) maxLocals = 4;
+ incStack();
+ incStack();
+ }
+
+ public void opc_dload_3() {
+ emitByte(opc_dload_3);
+ if (maxLocals < 5) maxLocals = 5;
+ incStack();
+ incStack();
+ }
+
+ public void opc_aload_0() {
+ emitByte(opc_aload_0);
+ if (maxLocals < 1) maxLocals = 1;
+ incStack();
+ }
+
+ public void opc_aload_1() {
+ emitByte(opc_aload_1);
+ if (maxLocals < 2) maxLocals = 2;
+ incStack();
+ }
+
+ public void opc_aload_2() {
+ emitByte(opc_aload_2);
+ if (maxLocals < 3) maxLocals = 3;
+ incStack();
+ }
+
+ public void opc_aload_3() {
+ emitByte(opc_aload_3);
+ if (maxLocals < 4) maxLocals = 4;
+ incStack();
+ }
+
+ public void opc_aaload() {
+ emitByte(opc_aaload);
+ decStack();
+ }
+
+ public void opc_astore_0() {
+ emitByte(opc_astore_0);
+ if (maxLocals < 1) maxLocals = 1;
+ decStack();
+ }
+
+ public void opc_astore_1() {
+ emitByte(opc_astore_1);
+ if (maxLocals < 2) maxLocals = 2;
+ decStack();
+ }
+
+ public void opc_astore_2() {
+ emitByte(opc_astore_2);
+ if (maxLocals < 3) maxLocals = 3;
+ decStack();
+ }
+
+ public void opc_astore_3() {
+ emitByte(opc_astore_3);
+ if (maxLocals < 4) maxLocals = 4;
+ decStack();
+ }
+
+ ////////////////////////
+ // Stack manipulation //
+ ////////////////////////
+
+ public void opc_pop() {
+ emitByte(opc_pop);
+ decStack();
+ }
+
+ public void opc_dup() {
+ emitByte(opc_dup);
+ incStack();
+ }
+
+ public void opc_dup_x1() {
+ emitByte(opc_dup_x1);
+ incStack();
+ }
+
+ public void opc_swap() {
+ emitByte(opc_swap);
+ }
+
+ ///////////////////////////////
+ // Widening conversions only //
+ ///////////////////////////////
+
+ public void opc_i2l() {
+ emitByte(opc_i2l);
+ }
+
+ public void opc_i2f() {
+ emitByte(opc_i2f);
+ }
+
+ public void opc_i2d() {
+ emitByte(opc_i2d);
+ }
+
+ public void opc_l2f() {
+ emitByte(opc_l2f);
+ }
+
+ public void opc_l2d() {
+ emitByte(opc_l2d);
+ }
+
+ public void opc_f2d() {
+ emitByte(opc_f2d);
+ }
+
+ //////////////////
+ // Control flow //
+ //////////////////
+
+ public void opc_ifeq(short bciOffset) {
+ emitByte(opc_ifeq);
+ emitShort(bciOffset);
+ decStack();
+ }
+
+ /** Control flow with forward-reference BCI. Stack assumes
+ straight-through control flow. */
+ public void opc_ifeq(Label l) {
+ short instrBCI = getLength();
+ emitByte(opc_ifeq);
+ l.add(this, instrBCI, getLength(), getStack() - 1);
+ emitShort((short) -1); // Must be patched later
+ }
+
+ public void opc_if_icmpeq(short bciOffset) {
+ emitByte(opc_if_icmpeq);
+ emitShort(bciOffset);
+ setStack(getStack() - 2);
+ }
+
+ /** Control flow with forward-reference BCI. Stack assumes straight
+ control flow. */
+ public void opc_if_icmpeq(Label l) {
+ short instrBCI = getLength();
+ emitByte(opc_if_icmpeq);
+ l.add(this, instrBCI, getLength(), getStack() - 2);
+ emitShort((short) -1); // Must be patched later
+ }
+
+ public void opc_goto(short bciOffset) {
+ emitByte(opc_goto);
+ emitShort(bciOffset);
+ }
+
+ /** Control flow with forward-reference BCI. Stack assumes straight
+ control flow. */
+ public void opc_goto(Label l) {
+ short instrBCI = getLength();
+ emitByte(opc_goto);
+ l.add(this, instrBCI, getLength(), getStack());
+ emitShort((short) -1); // Must be patched later
+ }
+
+ public void opc_ifnull(short bciOffset) {
+ emitByte(opc_ifnull);
+ emitShort(bciOffset);
+ decStack();
+ }
+
+ /** Control flow with forward-reference BCI. Stack assumes straight
+ control flow. */
+ public void opc_ifnull(Label l) {
+ short instrBCI = getLength();
+ emitByte(opc_ifnull);
+ l.add(this, instrBCI, getLength(), getStack() - 1);
+ emitShort((short) -1); // Must be patched later
+ decStack();
+ }
+
+ public void opc_ifnonnull(short bciOffset) {
+ emitByte(opc_ifnonnull);
+ emitShort(bciOffset);
+ decStack();
+ }
+
+ /** Control flow with forward-reference BCI. Stack assumes straight
+ control flow. */
+ public void opc_ifnonnull(Label l) {
+ short instrBCI = getLength();
+ emitByte(opc_ifnonnull);
+ l.add(this, instrBCI, getLength(), getStack() - 1);
+ emitShort((short) -1); // Must be patched later
+ decStack();
+ }
+
+ /////////////////////////
+ // Return instructions //
+ /////////////////////////
+
+ public void opc_ireturn() {
+ emitByte(opc_ireturn);
+ setStack(0);
+ }
+
+ public void opc_lreturn() {
+ emitByte(opc_lreturn);
+ setStack(0);
+ }
+
+ public void opc_freturn() {
+ emitByte(opc_freturn);
+ setStack(0);
+ }
+
+ public void opc_dreturn() {
+ emitByte(opc_dreturn);
+ setStack(0);
+ }
+
+ public void opc_areturn() {
+ emitByte(opc_areturn);
+ setStack(0);
+ }
+
+ public void opc_return() {
+ emitByte(opc_return);
+ setStack(0);
+ }
+
+ //////////////////////
+ // Field operations //
+ //////////////////////
+
+ public void opc_getstatic(short fieldIndex, int fieldSizeInStackSlots) {
+ emitByte(opc_getstatic);
+ emitShort(fieldIndex);
+ setStack(getStack() + fieldSizeInStackSlots);
+ }
+
+ public void opc_putstatic(short fieldIndex, int fieldSizeInStackSlots) {
+ emitByte(opc_putstatic);
+ emitShort(fieldIndex);
+ setStack(getStack() - fieldSizeInStackSlots);
+ }
+
+ public void opc_getfield(short fieldIndex, int fieldSizeInStackSlots) {
+ emitByte(opc_getfield);
+ emitShort(fieldIndex);
+ setStack(getStack() + fieldSizeInStackSlots - 1);
+ }
+
+ public void opc_putfield(short fieldIndex, int fieldSizeInStackSlots) {
+ emitByte(opc_putfield);
+ emitShort(fieldIndex);
+ setStack(getStack() - fieldSizeInStackSlots - 1);
+ }
+
+ ////////////////////////
+ // Method invocations //
+ ////////////////////////
+
+ /** Long and double arguments and return types count as 2 arguments;
+ other values count as 1. */
+ public void opc_invokevirtual(short methodIndex,
+ int numArgs,
+ int numReturnValues)
+ {
+ emitByte(opc_invokevirtual);
+ emitShort(methodIndex);
+ setStack(getStack() - numArgs - 1 + numReturnValues);
+ }
+
+ /** Long and double arguments and return types count as 2 arguments;
+ other values count as 1. */
+ public void opc_invokespecial(short methodIndex,
+ int numArgs,
+ int numReturnValues)
+ {
+ emitByte(opc_invokespecial);
+ emitShort(methodIndex);
+ setStack(getStack() - numArgs - 1 + numReturnValues);
+ }
+
+ /** Long and double arguments and return types count as 2 arguments;
+ other values count as 1. */
+ public void opc_invokestatic(short methodIndex,
+ int numArgs,
+ int numReturnValues)
+ {
+ emitByte(opc_invokestatic);
+ emitShort(methodIndex);
+ setStack(getStack() - numArgs + numReturnValues);
+ }
+
+ /** Long and double arguments and return types count as 2 arguments;
+ other values count as 1. */
+ public void opc_invokeinterface(short methodIndex,
+ int numArgs,
+ byte count,
+ int numReturnValues)
+ {
+ emitByte(opc_invokeinterface);
+ emitShort(methodIndex);
+ emitByte(count);
+ emitByte((byte) 0);
+ setStack(getStack() - numArgs - 1 + numReturnValues);
+ }
+
+ //////////////////
+ // Array length //
+ //////////////////
+
+ public void opc_arraylength() {
+ emitByte(opc_arraylength);
+ }
+
+ /////////
+ // New //
+ /////////
+
+ public void opc_new(short classIndex) {
+ emitByte(opc_new);
+ emitShort(classIndex);
+ incStack();
+ }
+
+ ////////////
+ // Athrow //
+ ////////////
+
+ public void opc_athrow() {
+ emitByte(opc_athrow);
+ setStack(1);
+ }
+
+ //////////////////////////////
+ // Checkcast and instanceof //
+ //////////////////////////////
+
+ /** Assumes the checkcast succeeds */
+ public void opc_checkcast(short classIndex) {
+ emitByte(opc_checkcast);
+ emitShort(classIndex);
+ }
+
+ public void opc_instanceof(short classIndex) {
+ emitByte(opc_instanceof);
+ emitShort(classIndex);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ClassFileConstants.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** Minimal set of class file constants for assembly of field and
+ method accessors. */
+
+interface ClassFileConstants {
+ // Constants
+ public static final byte opc_aconst_null = (byte) 0x1;
+ public static final byte opc_sipush = (byte) 0x11;
+ public static final byte opc_ldc = (byte) 0x12;
+
+ // Local variable loads and stores
+ public static final byte opc_iload_0 = (byte) 0x1a;
+ public static final byte opc_iload_1 = (byte) 0x1b;
+ public static final byte opc_iload_2 = (byte) 0x1c;
+ public static final byte opc_iload_3 = (byte) 0x1d;
+ public static final byte opc_lload_0 = (byte) 0x1e;
+ public static final byte opc_lload_1 = (byte) 0x1f;
+ public static final byte opc_lload_2 = (byte) 0x20;
+ public static final byte opc_lload_3 = (byte) 0x21;
+ public static final byte opc_fload_0 = (byte) 0x22;
+ public static final byte opc_fload_1 = (byte) 0x23;
+ public static final byte opc_fload_2 = (byte) 0x24;
+ public static final byte opc_fload_3 = (byte) 0x25;
+ public static final byte opc_dload_0 = (byte) 0x26;
+ public static final byte opc_dload_1 = (byte) 0x27;
+ public static final byte opc_dload_2 = (byte) 0x28;
+ public static final byte opc_dload_3 = (byte) 0x29;
+ public static final byte opc_aload_0 = (byte) 0x2a;
+ public static final byte opc_aload_1 = (byte) 0x2b;
+ public static final byte opc_aload_2 = (byte) 0x2c;
+ public static final byte opc_aload_3 = (byte) 0x2d;
+ public static final byte opc_aaload = (byte) 0x32;
+ public static final byte opc_astore_0 = (byte) 0x4b;
+ public static final byte opc_astore_1 = (byte) 0x4c;
+ public static final byte opc_astore_2 = (byte) 0x4d;
+ public static final byte opc_astore_3 = (byte) 0x4e;
+
+ // Stack manipulation
+ public static final byte opc_pop = (byte) 0x57;
+ public static final byte opc_dup = (byte) 0x59;
+ public static final byte opc_dup_x1 = (byte) 0x5a;
+ public static final byte opc_swap = (byte) 0x5f;
+
+ // Conversions
+ public static final byte opc_i2l = (byte) 0x85;
+ public static final byte opc_i2f = (byte) 0x86;
+ public static final byte opc_i2d = (byte) 0x87;
+ public static final byte opc_l2i = (byte) 0x88;
+ public static final byte opc_l2f = (byte) 0x89;
+ public static final byte opc_l2d = (byte) 0x8a;
+ public static final byte opc_f2i = (byte) 0x8b;
+ public static final byte opc_f2l = (byte) 0x8c;
+ public static final byte opc_f2d = (byte) 0x8d;
+ public static final byte opc_d2i = (byte) 0x8e;
+ public static final byte opc_d2l = (byte) 0x8f;
+ public static final byte opc_d2f = (byte) 0x90;
+ public static final byte opc_i2b = (byte) 0x91;
+ public static final byte opc_i2c = (byte) 0x92;
+ public static final byte opc_i2s = (byte) 0x93;
+
+ // Control flow
+ public static final byte opc_ifeq = (byte) 0x99;
+ public static final byte opc_if_icmpeq = (byte) 0x9f;
+ public static final byte opc_goto = (byte) 0xa7;
+
+ // Return instructions
+ public static final byte opc_ireturn = (byte) 0xac;
+ public static final byte opc_lreturn = (byte) 0xad;
+ public static final byte opc_freturn = (byte) 0xae;
+ public static final byte opc_dreturn = (byte) 0xaf;
+ public static final byte opc_areturn = (byte) 0xb0;
+ public static final byte opc_return = (byte) 0xb1;
+
+ // Field operations
+ public static final byte opc_getstatic = (byte) 0xb2;
+ public static final byte opc_putstatic = (byte) 0xb3;
+ public static final byte opc_getfield = (byte) 0xb4;
+ public static final byte opc_putfield = (byte) 0xb5;
+
+ // Method invocations
+ public static final byte opc_invokevirtual = (byte) 0xb6;
+ public static final byte opc_invokespecial = (byte) 0xb7;
+ public static final byte opc_invokestatic = (byte) 0xb8;
+ public static final byte opc_invokeinterface = (byte) 0xb9;
+
+ // Array length
+ public static final byte opc_arraylength = (byte) 0xbe;
+
+ // New
+ public static final byte opc_new = (byte) 0xbb;
+
+ // Athrow
+ public static final byte opc_athrow = (byte) 0xbf;
+
+ // Checkcast and instanceof
+ public static final byte opc_checkcast = (byte) 0xc0;
+ public static final byte opc_instanceof = (byte) 0xc1;
+
+ // Ifnull and ifnonnull
+ public static final byte opc_ifnull = (byte) 0xc6;
+ public static final byte opc_ifnonnull = (byte) 0xc7;
+
+ // Constant pool tags
+ public static final byte CONSTANT_Class = (byte) 7;
+ public static final byte CONSTANT_Fieldref = (byte) 9;
+ public static final byte CONSTANT_Methodref = (byte) 10;
+ public static final byte CONSTANT_InterfaceMethodref = (byte) 11;
+ public static final byte CONSTANT_NameAndType = (byte) 12;
+ public static final byte CONSTANT_String = (byte) 8;
+ public static final byte CONSTANT_Utf8 = (byte) 1;
+
+ // Access flags
+ public static final short ACC_PUBLIC = (short) 0x0001;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ConstantPool.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2003, 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
+ * 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.*;
+
+/** Provides reflective access to the constant pools of classes.
+ Currently this is needed to provide reflective access to annotations
+ but may be used by other internal subsystems in the future. */
+
+public class ConstantPool {
+ // Number of entries in this constant pool (= maximum valid constant pool index)
+ public int getSize() { return getSize0 (constantPoolOop); }
+ public Class<?> getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
+ public Class<?> getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
+ // Returns a class reference index for a method or a field.
+ public int getClassRefIndexAt(int index) {
+ return getClassRefIndexAt0(constantPoolOop, index);
+ }
+ // Returns either a Method or Constructor.
+ // Static initializers are returned as Method objects.
+ public Member getMethodAt (int index) { return getMethodAt0 (constantPoolOop, index); }
+ public Member getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
+ public Field getFieldAt (int index) { return getFieldAt0 (constantPoolOop, index); }
+ public Field getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }
+ // Fetches the class name, member (field, method or interface
+ // method) name, and type descriptor as an array of three Strings
+ public String[] getMemberRefInfoAt (int index) { return getMemberRefInfoAt0 (constantPoolOop, index); }
+ // Returns a name and type reference index for a method, a field or an invokedynamic.
+ public int getNameAndTypeRefIndexAt(int index) {
+ return getNameAndTypeRefIndexAt0(constantPoolOop, index);
+ }
+ // Fetches the name and type from name_and_type index as an array of two Strings
+ public String[] getNameAndTypeRefInfoAt(int index) {
+ return getNameAndTypeRefInfoAt0(constantPoolOop, index);
+ }
+ public int getIntAt (int index) { return getIntAt0 (constantPoolOop, index); }
+ public long getLongAt (int index) { return getLongAt0 (constantPoolOop, index); }
+ public float getFloatAt (int index) { return getFloatAt0 (constantPoolOop, index); }
+ public double getDoubleAt (int index) { return getDoubleAt0 (constantPoolOop, index); }
+ public String getStringAt (int index) { return getStringAt0 (constantPoolOop, index); }
+ public String getUTF8At (int index) { return getUTF8At0 (constantPoolOop, index); }
+ public Tag getTagAt(int index) {
+ return Tag.valueOf(getTagAt0(constantPoolOop, index));
+ }
+
+ public static enum Tag {
+ UTF8(1),
+ INTEGER(3),
+ FLOAT(4),
+ LONG(5),
+ DOUBLE(6),
+ CLASS(7),
+ STRING(8),
+ FIELDREF(9),
+ METHODREF(10),
+ INTERFACEMETHODREF(11),
+ NAMEANDTYPE(12),
+ METHODHANDLE(15),
+ METHODTYPE(16),
+ INVOKEDYNAMIC(18),
+ INVALID(0);
+
+ private final int tagCode;
+
+ private Tag(int tagCode) {
+ this.tagCode = tagCode;
+ }
+
+ private static Tag valueOf(byte v) {
+ for (Tag tag : Tag.values()) {
+ if (tag.tagCode == v) {
+ return tag;
+ }
+ }
+ throw new IllegalArgumentException("Unknown constant pool tag code " + v);
+ }
+ }
+ //---------------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ static {
+ Reflection.registerFieldsToFilter(ConstantPool.class, new String[] { "constantPoolOop" });
+ }
+
+ // HotSpot-internal constant pool object (set by the VM, name known to the VM)
+ private Object constantPoolOop;
+
+ private native int getSize0 (Object constantPoolOop);
+ private native Class<?> getClassAt0 (Object constantPoolOop, int index);
+ private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);
+ private native int getClassRefIndexAt0 (Object constantPoolOop, int index);
+ private native Member getMethodAt0 (Object constantPoolOop, int index);
+ private native Member getMethodAtIfLoaded0(Object constantPoolOop, int index);
+ private native Field getFieldAt0 (Object constantPoolOop, int index);
+ private native Field getFieldAtIfLoaded0 (Object constantPoolOop, int index);
+ private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
+ private native int getNameAndTypeRefIndexAt0(Object constantPoolOop, int index);
+ private native String[] getNameAndTypeRefInfoAt0(Object constantPoolOop, int index);
+ private native int getIntAt0 (Object constantPoolOop, int index);
+ private native long getLongAt0 (Object constantPoolOop, int index);
+ private native float getFloatAt0 (Object constantPoolOop, int index);
+ private native double getDoubleAt0 (Object constantPoolOop, int index);
+ private native String getStringAt0 (Object constantPoolOop, int index);
+ private native String getUTF8At0 (Object constantPoolOop, int index);
+ private native byte getTagAt0 (Object constantPoolOop, int index);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ConstructorAccessor.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.InvocationTargetException;
+
+/** This interface provides the declaration for
+ java.lang.reflect.Constructor.invoke(). Each Constructor object is
+ configured with a (possibly dynamically-generated) class which
+ implements this interface. */
+
+public interface ConstructorAccessor {
+ /** Matches specification in {@link java.lang.reflect.Constructor} */
+ public Object newInstance(Object[] args)
+ throws InstantiationException,
+ IllegalArgumentException,
+ InvocationTargetException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ConstructorAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.InvocationTargetException;
+
+/** Package-private implementation of the ConstructorAccessor
+ interface which has access to all classes and all fields,
+ regardless of language restrictions. See MagicAccessorImpl. */
+
+abstract class ConstructorAccessorImpl extends MagicAccessorImpl
+ implements ConstructorAccessor {
+ /** Matches specification in {@link java.lang.reflect.Constructor} */
+ public abstract Object newInstance(Object[] args)
+ throws InstantiationException,
+ IllegalArgumentException,
+ InvocationTargetException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/DelegatingConstructorAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.InvocationTargetException;
+
+/** Delegates its invocation to another ConstructorAccessorImpl and can
+ change its delegate at run time. */
+
+class DelegatingConstructorAccessorImpl extends ConstructorAccessorImpl {
+ private ConstructorAccessorImpl delegate;
+
+ DelegatingConstructorAccessorImpl(ConstructorAccessorImpl delegate) {
+ setDelegate(delegate);
+ }
+
+ public Object newInstance(Object[] args)
+ throws InstantiationException,
+ IllegalArgumentException,
+ InvocationTargetException
+ {
+ return delegate.newInstance(args);
+ }
+
+ void setDelegate(ConstructorAccessorImpl delegate) {
+ this.delegate = delegate;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/DelegatingMethodAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.InvocationTargetException;
+
+/** Delegates its invocation to another MethodAccessorImpl and can
+ change its delegate at run time. */
+
+class DelegatingMethodAccessorImpl extends MethodAccessorImpl {
+ private MethodAccessorImpl delegate;
+
+ DelegatingMethodAccessorImpl(MethodAccessorImpl delegate) {
+ setDelegate(delegate);
+ }
+
+ public Object invoke(Object obj, Object[] args)
+ throws IllegalArgumentException, InvocationTargetException
+ {
+ return delegate.invoke(obj, args);
+ }
+
+ void setDelegate(MethodAccessorImpl delegate) {
+ this.delegate = delegate;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/FieldAccessor.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** This interface provides the declarations for the accessor methods
+ of java.lang.reflect.Field. Each Field object is configured with a
+ (possibly dynamically-generated) class which implements this
+ interface. */
+
+public interface FieldAccessor {
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public Object get(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public boolean getBoolean(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public byte getByte(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public char getChar(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public short getShort(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public int getInt(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public long getLong(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public float getFloat(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public double getDouble(Object obj) throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/FieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** Package-private implementation of the FieldAccessor interface
+ which has access to all classes and all fields, regardless of
+ language restrictions. See MagicAccessorImpl. */
+
+abstract class FieldAccessorImpl extends MagicAccessorImpl
+ implements FieldAccessor {
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract Object get(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract boolean getBoolean(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract byte getByte(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract char getChar(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract short getShort(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract int getInt(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract long getLong(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract float getFloat(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract double getDouble(Object obj)
+ throws IllegalArgumentException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException;
+
+ /** Matches specification in {@link java.lang.reflect.Field} */
+ public abstract void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/InstantiationExceptionConstructorAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+/** Throws an InstantiationException with given error message upon
+ newInstance() call */
+
+class InstantiationExceptionConstructorAccessorImpl
+ extends ConstructorAccessorImpl {
+ private final String message;
+
+ InstantiationExceptionConstructorAccessorImpl(String message) {
+ this.message = message;
+ }
+
+ public Object newInstance(Object[] args)
+ throws InstantiationException,
+ IllegalArgumentException,
+ InvocationTargetException
+ {
+ if (message == null) {
+ throw new InstantiationException();
+ }
+ throw new InstantiationException(message);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/Label.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2001, 2011, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/** Allows forward references in bytecode streams emitted by
+ ClassFileAssembler. Assumes that the start of the method body is
+ the first byte in the assembler's buffer. May be used at more than
+ one branch site. */
+
+class Label {
+ static class PatchInfo {
+ PatchInfo(ClassFileAssembler asm,
+ short instrBCI,
+ short patchBCI,
+ int stackDepth)
+ {
+ this.asm = asm;
+ this.instrBCI = instrBCI;
+ this.patchBCI = patchBCI;
+ this.stackDepth = stackDepth;
+ }
+ // This won't work for more than one assembler anyway, so this is
+ // unnecessary
+ final ClassFileAssembler asm;
+ final short instrBCI;
+ final short patchBCI;
+ final int stackDepth;
+ }
+ private final List<PatchInfo> patches = new ArrayList<>();
+
+ public Label() {
+ }
+
+ void add(ClassFileAssembler asm,
+ short instrBCI,
+ short patchBCI,
+ int stackDepth)
+ {
+ patches.add(new PatchInfo(asm, instrBCI, patchBCI, stackDepth));
+ }
+
+ public void bind() {
+ for (PatchInfo patch : patches){
+ short curBCI = patch.asm.getLength();
+ short offset = (short) (curBCI - patch.instrBCI);
+ patch.asm.emitShort(patch.patchBCI, offset);
+ patch.asm.setStack(patch.stackDepth);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/LangReflectAccess.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,115 @@
+/*
+ * 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
+ * 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.*;
+
+/** An interface which gives privileged packages Java-level access to
+ internals of java.lang.reflect. */
+
+public interface LangReflectAccess {
+ /** Creates a new java.lang.reflect.Field. Access checks as per
+ java.lang.reflect.AccessibleObject are not overridden. */
+ public Field newField(Class<?> declaringClass,
+ String name,
+ Class<?> type,
+ int modifiers,
+ int slot,
+ String signature,
+ byte[] annotations);
+
+ /** Creates a new java.lang.reflect.Method. Access checks as per
+ java.lang.reflect.AccessibleObject are not overridden. */
+ public Method newMethod(Class<?> declaringClass,
+ String name,
+ Class<?>[] parameterTypes,
+ Class<?> returnType,
+ Class<?>[] checkedExceptions,
+ int modifiers,
+ int slot,
+ String signature,
+ byte[] annotations,
+ byte[] parameterAnnotations,
+ byte[] annotationDefault);
+
+ /** Creates a new java.lang.reflect.Constructor. Access checks as
+ per java.lang.reflect.AccessibleObject are not overridden. */
+ public <T> Constructor<T> newConstructor(Class<T> declaringClass,
+ Class<?>[] parameterTypes,
+ Class<?>[] checkedExceptions,
+ int modifiers,
+ int slot,
+ String signature,
+ byte[] annotations,
+ byte[] parameterAnnotations);
+
+ /** Gets the MethodAccessor object for a java.lang.reflect.Method */
+ public MethodAccessor getMethodAccessor(Method m);
+
+ /** Sets the MethodAccessor object for a java.lang.reflect.Method */
+ public void setMethodAccessor(Method m, MethodAccessor accessor);
+
+ /** Gets the ConstructorAccessor object for a
+ java.lang.reflect.Constructor */
+ public ConstructorAccessor getConstructorAccessor(Constructor<?> c);
+
+ /** Sets the ConstructorAccessor object for a
+ java.lang.reflect.Constructor */
+ public void setConstructorAccessor(Constructor<?> c,
+ ConstructorAccessor accessor);
+
+ /** Gets the byte[] that encodes TypeAnnotations on an Executable. */
+ public byte[] getExecutableTypeAnnotationBytes(Executable ex);
+
+ /** Gets the "slot" field from a Constructor (used for serialization) */
+ public int getConstructorSlot(Constructor<?> c);
+
+ /** Gets the "signature" field from a Constructor (used for serialization) */
+ public String getConstructorSignature(Constructor<?> c);
+
+ /** Gets the "annotations" field from a Constructor (used for serialization) */
+ public byte[] getConstructorAnnotations(Constructor<?> c);
+
+ /** Gets the "parameterAnnotations" field from a Constructor (used for serialization) */
+ public byte[] getConstructorParameterAnnotations(Constructor<?> c);
+
+ //
+ // Copying routines, needed to quickly fabricate new Field,
+ // Method, and Constructor objects from templates
+ //
+
+ /** Makes a "child" copy of a Method */
+ public Method copyMethod(Method arg);
+
+ /** Makes a copy of this non-root a Method */
+ public Method leafCopyMethod(Method arg);
+
+ /** Makes a "child" copy of a Field */
+ public Field copyField(Field arg);
+
+ /** Makes a "child" copy of a Constructor */
+ public <T> Constructor<T> copyConstructor(Constructor<T> arg);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/MagicAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** <P> MagicAccessorImpl (named for parity with FieldAccessorImpl and
+ others, not because it actually implements an interface) is a
+ marker class in the hierarchy. All subclasses of this class are
+ "magically" granted access by the VM to otherwise inaccessible
+ fields and methods of other classes. It is used to hold the code
+ for dynamically-generated FieldAccessorImpl and MethodAccessorImpl
+ subclasses. (Use of the word "unsafe" was avoided in this class's
+ name to avoid confusion with {@link jdk.internal.misc.Unsafe}.) </P>
+
+ <P> The bug fix for 4486457 also necessitated disabling
+ verification for this class and all subclasses, as opposed to just
+ SerializationConstructorAccessorImpl and subclasses, to avoid
+ having to indicate to the VM which of these dynamically-generated
+ stub classes were known to be able to pass the verifier. </P>
+
+ <P> Do not change the name of this class without also changing the
+ VM's code. </P> */
+
+class MagicAccessorImpl {
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/MethodAccessor.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.InvocationTargetException;
+
+/** This interface provides the declaration for
+ java.lang.reflect.Method.invoke(). Each Method object is
+ configured with a (possibly dynamically-generated) class which
+ implements this interface.
+*/
+
+public interface MethodAccessor {
+ /** Matches specification in {@link java.lang.reflect.Method} */
+ public Object invoke(Object obj, Object[] args)
+ throws IllegalArgumentException, InvocationTargetException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/MethodAccessorGenerator.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,780 @@
+/*
+ * 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
+ * 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/** Generator for sun.reflect.MethodAccessor and
+ sun.reflect.ConstructorAccessor objects using bytecodes to
+ implement reflection. A java.lang.reflect.Method or
+ java.lang.reflect.Constructor object can delegate its invoke or
+ newInstance method to an accessor using native code or to one
+ generated by this class. (Methods and Constructors were merged
+ together in this class to ensure maximum code sharing.) */
+
+class MethodAccessorGenerator extends AccessorGenerator {
+
+ private static final short NUM_BASE_CPOOL_ENTRIES = (short) 12;
+ // One for invoke() plus one for constructor
+ private static final short NUM_METHODS = (short) 2;
+ // Only used if forSerialization is true
+ private static final short NUM_SERIALIZATION_CPOOL_ENTRIES = (short) 2;
+
+ private static volatile int methodSymnum;
+ private static volatile int constructorSymnum;
+ private static volatile int serializationConstructorSymnum;
+
+ private Class<?> declaringClass;
+ private Class<?>[] parameterTypes;
+ private Class<?> returnType;
+ private boolean isConstructor;
+ private boolean forSerialization;
+
+ private short targetMethodRef;
+ private short invokeIdx;
+ private short invokeDescriptorIdx;
+ // Constant pool index of CONSTANT_Class_info for first
+ // non-primitive parameter type. Should be incremented by 2.
+ private short nonPrimitiveParametersBaseIdx;
+
+ MethodAccessorGenerator() {
+ }
+
+ /** This routine is not thread-safe */
+ public MethodAccessor generateMethod(Class<?> declaringClass,
+ String name,
+ Class<?>[] parameterTypes,
+ Class<?> returnType,
+ Class<?>[] checkedExceptions,
+ int modifiers)
+ {
+ return (MethodAccessor) generate(declaringClass,
+ name,
+ parameterTypes,
+ returnType,
+ checkedExceptions,
+ modifiers,
+ false,
+ false,
+ null);
+ }
+
+ /** This routine is not thread-safe */
+ public ConstructorAccessor generateConstructor(Class<?> declaringClass,
+ Class<?>[] parameterTypes,
+ Class<?>[] checkedExceptions,
+ int modifiers)
+ {
+ return (ConstructorAccessor) generate(declaringClass,
+ "<init>",
+ parameterTypes,
+ Void.TYPE,
+ checkedExceptions,
+ modifiers,
+ true,
+ false,
+ null);
+ }
+
+ /** This routine is not thread-safe */
+ public SerializationConstructorAccessorImpl
+ generateSerializationConstructor(Class<?> declaringClass,
+ Class<?>[] parameterTypes,
+ Class<?>[] checkedExceptions,
+ int modifiers,
+ Class<?> targetConstructorClass)
+ {
+ return (SerializationConstructorAccessorImpl)
+ generate(declaringClass,
+ "<init>",
+ parameterTypes,
+ Void.TYPE,
+ checkedExceptions,
+ modifiers,
+ true,
+ true,
+ targetConstructorClass);
+ }
+
+ /** This routine is not thread-safe */
+ private MagicAccessorImpl generate(final Class<?> declaringClass,
+ String name,
+ Class<?>[] parameterTypes,
+ Class<?> returnType,
+ Class<?>[] checkedExceptions,
+ int modifiers,
+ boolean isConstructor,
+ boolean forSerialization,
+ Class<?> serializationTargetClass)
+ {
+ ByteVector vec = ByteVectorFactory.create();
+ asm = new ClassFileAssembler(vec);
+ this.declaringClass = declaringClass;
+ this.parameterTypes = parameterTypes;
+ this.returnType = returnType;
+ this.modifiers = modifiers;
+ this.isConstructor = isConstructor;
+ this.forSerialization = forSerialization;
+
+ asm.emitMagicAndVersion();
+
+ // Constant pool entries:
+ // ( * = Boxing information: optional)
+ // (+ = Shared entries provided by AccessorGenerator)
+ // (^ = Only present if generating SerializationConstructorAccessor)
+ // [UTF-8] [This class's name]
+ // [CONSTANT_Class_info] for above
+ // [UTF-8] "jdk/internal/reflect/{MethodAccessorImpl,ConstructorAccessorImpl,SerializationConstructorAccessorImpl}"
+ // [CONSTANT_Class_info] for above
+ // [UTF-8] [Target class's name]
+ // [CONSTANT_Class_info] for above
+ // ^ [UTF-8] [Serialization: Class's name in which to invoke constructor]
+ // ^ [CONSTANT_Class_info] for above
+ // [UTF-8] target method or constructor name
+ // [UTF-8] target method or constructor signature
+ // [CONSTANT_NameAndType_info] for above
+ // [CONSTANT_Methodref_info or CONSTANT_InterfaceMethodref_info] for target method
+ // [UTF-8] "invoke" or "newInstance"
+ // [UTF-8] invoke or newInstance descriptor
+ // [UTF-8] descriptor for type of non-primitive parameter 1
+ // [CONSTANT_Class_info] for type of non-primitive parameter 1
+ // ...
+ // [UTF-8] descriptor for type of non-primitive parameter n
+ // [CONSTANT_Class_info] for type of non-primitive parameter n
+ // + [UTF-8] "java/lang/Exception"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/ClassCastException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/NullPointerException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/IllegalArgumentException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "java/lang/InvocationTargetException"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "<init>"
+ // + [UTF-8] "()V"
+ // + [CONSTANT_NameAndType_info] for above
+ // + [CONSTANT_Methodref_info] for NullPointerException's constructor
+ // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor
+ // + [UTF-8] "(Ljava/lang/String;)V"
+ // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/String;)V"
+ // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor taking a String
+ // + [UTF-8] "(Ljava/lang/Throwable;)V"
+ // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/Throwable;)V"
+ // + [CONSTANT_Methodref_info] for InvocationTargetException's constructor
+ // + [CONSTANT_Methodref_info] for "super()"
+ // + [UTF-8] "java/lang/Object"
+ // + [CONSTANT_Class_info] for above
+ // + [UTF-8] "toString"
+ // + [UTF-8] "()Ljava/lang/String;"
+ // + [CONSTANT_NameAndType_info] for "toString()Ljava/lang/String;"
+ // + [CONSTANT_Methodref_info] for Object's toString method
+ // + [UTF-8] "Code"
+ // + [UTF-8] "Exceptions"
+ // * [UTF-8] "java/lang/Boolean"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(Z)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "booleanValue"
+ // * [UTF-8] "()Z"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Byte"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(B)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "byteValue"
+ // * [UTF-8] "()B"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Character"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(C)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "charValue"
+ // * [UTF-8] "()C"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Double"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(D)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "doubleValue"
+ // * [UTF-8] "()D"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Float"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(F)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "floatValue"
+ // * [UTF-8] "()F"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Integer"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(I)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "intValue"
+ // * [UTF-8] "()I"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Long"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(J)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "longValue"
+ // * [UTF-8] "()J"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "java/lang/Short"
+ // * [CONSTANT_Class_info] for above
+ // * [UTF-8] "(S)V"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+ // * [UTF-8] "shortValue"
+ // * [UTF-8] "()S"
+ // * [CONSTANT_NameAndType_info] for above
+ // * [CONSTANT_Methodref_info] for above
+
+ short numCPEntries = NUM_BASE_CPOOL_ENTRIES + NUM_COMMON_CPOOL_ENTRIES;
+ boolean usesPrimitives = usesPrimitiveTypes();
+ if (usesPrimitives) {
+ numCPEntries += NUM_BOXING_CPOOL_ENTRIES;
+ }
+ if (forSerialization) {
+ numCPEntries += NUM_SERIALIZATION_CPOOL_ENTRIES;
+ }
+
+ // Add in variable-length number of entries to be able to describe
+ // non-primitive parameter types and checked exceptions.
+ numCPEntries += (short) (2 * numNonPrimitiveParameterTypes());
+
+ asm.emitShort(add(numCPEntries, S1));
+
+ final String generatedName = generateName(isConstructor, forSerialization);
+ asm.emitConstantPoolUTF8(generatedName);
+ asm.emitConstantPoolClass(asm.cpi());
+ thisClass = asm.cpi();
+ if (isConstructor) {
+ if (forSerialization) {
+ asm.emitConstantPoolUTF8
+ ("jdk/internal/reflect/SerializationConstructorAccessorImpl");
+ } else {
+ asm.emitConstantPoolUTF8("jdk/internal/reflect/ConstructorAccessorImpl");
+ }
+ } else {
+ asm.emitConstantPoolUTF8("jdk/internal/reflect/MethodAccessorImpl");
+ }
+ asm.emitConstantPoolClass(asm.cpi());
+ superClass = asm.cpi();
+ asm.emitConstantPoolUTF8(getClassName(declaringClass, false));
+ asm.emitConstantPoolClass(asm.cpi());
+ targetClass = asm.cpi();
+ short serializationTargetClassIdx = (short) 0;
+ if (forSerialization) {
+ asm.emitConstantPoolUTF8(getClassName(serializationTargetClass, false));
+ asm.emitConstantPoolClass(asm.cpi());
+ serializationTargetClassIdx = asm.cpi();
+ }
+ asm.emitConstantPoolUTF8(name);
+ asm.emitConstantPoolUTF8(buildInternalSignature());
+ asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
+ if (isInterface()) {
+ asm.emitConstantPoolInterfaceMethodref(targetClass, asm.cpi());
+ } else {
+ if (forSerialization) {
+ asm.emitConstantPoolMethodref(serializationTargetClassIdx, asm.cpi());
+ } else {
+ asm.emitConstantPoolMethodref(targetClass, asm.cpi());
+ }
+ }
+ targetMethodRef = asm.cpi();
+ if (isConstructor) {
+ asm.emitConstantPoolUTF8("newInstance");
+ } else {
+ asm.emitConstantPoolUTF8("invoke");
+ }
+ invokeIdx = asm.cpi();
+ if (isConstructor) {
+ asm.emitConstantPoolUTF8("([Ljava/lang/Object;)Ljava/lang/Object;");
+ } else {
+ asm.emitConstantPoolUTF8
+ ("(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;");
+ }
+ invokeDescriptorIdx = asm.cpi();
+
+ // Output class information for non-primitive parameter types
+ nonPrimitiveParametersBaseIdx = add(asm.cpi(), S2);
+ for (int i = 0; i < parameterTypes.length; i++) {
+ Class<?> c = parameterTypes[i];
+ if (!isPrimitive(c)) {
+ asm.emitConstantPoolUTF8(getClassName(c, false));
+ asm.emitConstantPoolClass(asm.cpi());
+ }
+ }
+
+ // Entries common to FieldAccessor, MethodAccessor and ConstructorAccessor
+ emitCommonConstantPoolEntries();
+
+ // Boxing entries
+ if (usesPrimitives) {
+ emitBoxingContantPoolEntries();
+ }
+
+ if (asm.cpi() != numCPEntries) {
+ throw new InternalError("Adjust this code (cpi = " + asm.cpi() +
+ ", numCPEntries = " + numCPEntries + ")");
+ }
+
+ // Access flags
+ asm.emitShort(ACC_PUBLIC);
+
+ // This class
+ asm.emitShort(thisClass);
+
+ // Superclass
+ asm.emitShort(superClass);
+
+ // Interfaces count and interfaces
+ asm.emitShort(S0);
+
+ // Fields count and fields
+ asm.emitShort(S0);
+
+ // Methods count and methods
+ asm.emitShort(NUM_METHODS);
+
+ emitConstructor();
+ emitInvoke();
+
+ // Additional attributes (none)
+ asm.emitShort(S0);
+
+ // Load class
+ vec.trim();
+ final byte[] bytes = vec.getData();
+ // Note: the class loader is the only thing that really matters
+ // here -- it's important to get the generated code into the
+ // same namespace as the target class. Since the generated code
+ // is privileged anyway, the protection domain probably doesn't
+ // matter.
+ return AccessController.doPrivileged(
+ new PrivilegedAction<MagicAccessorImpl>() {
+ public MagicAccessorImpl run() {
+ try {
+ return (MagicAccessorImpl)
+ ClassDefiner.defineClass
+ (generatedName,
+ bytes,
+ 0,
+ bytes.length,
+ declaringClass.getClassLoader()).newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new InternalError(e);
+ }
+ }
+ });
+ }
+
+ /** This emits the code for either invoke() or newInstance() */
+ private void emitInvoke() {
+ // NOTE that this code will only handle 65535 parameters since we
+ // use the sipush instruction to get the array index on the
+ // operand stack.
+ if (parameterTypes.length > 65535) {
+ throw new InternalError("Can't handle more than 65535 parameters");
+ }
+
+ // Generate code into fresh code buffer
+ ClassFileAssembler cb = new ClassFileAssembler();
+ if (isConstructor) {
+ // 1 incoming argument
+ cb.setMaxLocals(2);
+ } else {
+ // 2 incoming arguments
+ cb.setMaxLocals(3);
+ }
+
+ short illegalArgStartPC = 0;
+
+ if (isConstructor) {
+ // Instantiate target class before continuing
+ // new <target class type>
+ // dup
+ cb.opc_new(targetClass);
+ cb.opc_dup();
+ } else {
+ // Setup before iterating down argument list
+ if (isPrimitive(returnType)) {
+ // new <boxing type for primitive type>
+ // dup
+ // ... (see below:)
+ // invokespecial <constructor for boxing type for primitive type>
+ // areturn
+ cb.opc_new(indexForPrimitiveType(returnType));
+ cb.opc_dup();
+ }
+
+ // Get target object on operand stack if necessary.
+
+ // We need to do an explicit null check here; we won't see
+ // NullPointerExceptions from the invoke bytecode, since it's
+ // covered by an exception handler.
+ if (!isStatic()) {
+ // aload_1
+ // ifnonnull <checkcast label>
+ // new <NullPointerException>
+ // dup
+ // invokespecial <NullPointerException ctor>
+ // athrow
+ // <checkcast label:>
+ // aload_1
+ // checkcast <target class's type>
+ cb.opc_aload_1();
+ Label l = new Label();
+ cb.opc_ifnonnull(l);
+ cb.opc_new(nullPointerClass);
+ cb.opc_dup();
+ cb.opc_invokespecial(nullPointerCtorIdx, 0, 0);
+ cb.opc_athrow();
+ l.bind();
+ illegalArgStartPC = cb.getLength();
+ cb.opc_aload_1();
+ cb.opc_checkcast(targetClass);
+ }
+ }
+
+ // Have to check length of incoming array and throw
+ // IllegalArgumentException if not correct. A concession to the
+ // JCK (isn't clearly specified in the spec): we allow null in the
+ // case where the argument list is zero length.
+ // if no-arg:
+ // aload_2 | aload_1 (Method | Constructor)
+ // ifnull <success label>
+ // aload_2 | aload_1
+ // arraylength
+ // sipush <num parameter types>
+ // if_icmpeq <success label>
+ // new <IllegalArgumentException>
+ // dup
+ // invokespecial <IllegalArgumentException ctor>
+ // athrow
+ // <success label:>
+ Label successLabel = new Label();
+ if (parameterTypes.length == 0) {
+ if (isConstructor) {
+ cb.opc_aload_1();
+ } else {
+ cb.opc_aload_2();
+ }
+ cb.opc_ifnull(successLabel);
+ }
+ if (isConstructor) {
+ cb.opc_aload_1();
+ } else {
+ cb.opc_aload_2();
+ }
+ cb.opc_arraylength();
+ cb.opc_sipush((short) parameterTypes.length);
+ cb.opc_if_icmpeq(successLabel);
+ cb.opc_new(illegalArgumentClass);
+ cb.opc_dup();
+ cb.opc_invokespecial(illegalArgumentCtorIdx, 0, 0);
+ cb.opc_athrow();
+ successLabel.bind();
+
+ // Iterate through incoming actual parameters, ensuring that each
+ // is compatible with the formal parameter type, and pushing the
+ // actual on the operand stack (unboxing and widening if necessary).
+
+ short paramTypeCPIdx = nonPrimitiveParametersBaseIdx;
+ Label nextParamLabel = null;
+ byte count = 1; // both invokeinterface opcode's "count" as well as
+ // num args of other invoke bytecodes
+ for (int i = 0; i < parameterTypes.length; i++) {
+ Class<?> paramType = parameterTypes[i];
+ count += (byte) typeSizeInStackSlots(paramType);
+ if (nextParamLabel != null) {
+ nextParamLabel.bind();
+ nextParamLabel = null;
+ }
+ // aload_2 | aload_1
+ // sipush <index>
+ // aaload
+ if (isConstructor) {
+ cb.opc_aload_1();
+ } else {
+ cb.opc_aload_2();
+ }
+ cb.opc_sipush((short) i);
+ cb.opc_aaload();
+ if (isPrimitive(paramType)) {
+ // Unboxing code.
+ // Put parameter into temporary local variable
+ // astore_3 | astore_2
+ if (isConstructor) {
+ cb.opc_astore_2();
+ } else {
+ cb.opc_astore_3();
+ }
+
+ // repeat for all possible widening conversions:
+ // aload_3 | aload_2
+ // instanceof <primitive boxing type>
+ // ifeq <next unboxing label>
+ // aload_3 | aload_2
+ // checkcast <primitive boxing type> // Note: this is "redundant",
+ // // but necessary for the verifier
+ // invokevirtual <unboxing method>
+ // <widening conversion bytecode, if necessary>
+ // goto <next parameter label>
+ // <next unboxing label:> ...
+ // last unboxing label:
+ // new <IllegalArgumentException>
+ // dup
+ // invokespecial <IllegalArgumentException ctor>
+ // athrow
+
+ Label l = null; // unboxing label
+ nextParamLabel = new Label();
+
+ for (int j = 0; j < primitiveTypes.length; j++) {
+ Class<?> c = primitiveTypes[j];
+ if (canWidenTo(c, paramType)) {
+ if (l != null) {
+ l.bind();
+ }
+ // Emit checking and unboxing code for this type
+ if (isConstructor) {
+ cb.opc_aload_2();
+ } else {
+ cb.opc_aload_3();
+ }
+ cb.opc_instanceof(indexForPrimitiveType(c));
+ l = new Label();
+ cb.opc_ifeq(l);
+ if (isConstructor) {
+ cb.opc_aload_2();
+ } else {
+ cb.opc_aload_3();
+ }
+ cb.opc_checkcast(indexForPrimitiveType(c));
+ cb.opc_invokevirtual(unboxingMethodForPrimitiveType(c),
+ 0,
+ typeSizeInStackSlots(c));
+ emitWideningBytecodeForPrimitiveConversion(cb,
+ c,
+ paramType);
+ cb.opc_goto(nextParamLabel);
+ }
+ }
+
+ if (l == null) {
+ throw new InternalError
+ ("Must have found at least identity conversion");
+ }
+
+ // Fell through; given object is null or invalid. According to
+ // the spec, we can throw IllegalArgumentException for both of
+ // these cases.
+
+ l.bind();
+ cb.opc_new(illegalArgumentClass);
+ cb.opc_dup();
+ cb.opc_invokespecial(illegalArgumentCtorIdx, 0, 0);
+ cb.opc_athrow();
+ } else {
+ // Emit appropriate checkcast
+ cb.opc_checkcast(paramTypeCPIdx);
+ paramTypeCPIdx = add(paramTypeCPIdx, S2);
+ // Fall through to next argument
+ }
+ }
+ // Bind last goto if present
+ if (nextParamLabel != null) {
+ nextParamLabel.bind();
+ }
+
+ short invokeStartPC = cb.getLength();
+
+ // OK, ready to perform the invocation.
+ if (isConstructor) {
+ cb.opc_invokespecial(targetMethodRef, count, 0);
+ } else {
+ if (isStatic()) {
+ cb.opc_invokestatic(targetMethodRef,
+ count,
+ typeSizeInStackSlots(returnType));
+ } else {
+ if (isInterface()) {
+ if (isPrivate()) {
+ cb.opc_invokespecial(targetMethodRef, count, 0);
+ } else {
+ cb.opc_invokeinterface(targetMethodRef,
+ count,
+ count,
+ typeSizeInStackSlots(returnType));
+ }
+ } else {
+ cb.opc_invokevirtual(targetMethodRef,
+ count,
+ typeSizeInStackSlots(returnType));
+ }
+ }
+ }
+
+ short invokeEndPC = cb.getLength();
+
+ if (!isConstructor) {
+ // Box return value if necessary
+ if (isPrimitive(returnType)) {
+ cb.opc_invokestatic(boxingMethodForPrimitiveType(returnType),
+ typeSizeInStackSlots(returnType),
+ 0);
+ } else if (returnType == Void.TYPE) {
+ cb.opc_aconst_null();
+ }
+ }
+ cb.opc_areturn();
+
+ // We generate two exception handlers; one which is responsible
+ // for catching ClassCastException and NullPointerException and
+ // throwing IllegalArgumentException, and the other which catches
+ // all java/lang/Throwable objects thrown from the target method
+ // and wraps them in InvocationTargetExceptions.
+
+ short classCastHandler = cb.getLength();
+
+ // ClassCast, etc. exception handler
+ cb.setStack(1);
+ cb.opc_invokespecial(toStringIdx, 0, 1);
+ cb.opc_new(illegalArgumentClass);
+ cb.opc_dup_x1();
+ cb.opc_swap();
+ cb.opc_invokespecial(illegalArgumentStringCtorIdx, 1, 0);
+ cb.opc_athrow();
+
+ short invocationTargetHandler = cb.getLength();
+
+ // InvocationTargetException exception handler
+ cb.setStack(1);
+ cb.opc_new(invocationTargetClass);
+ cb.opc_dup_x1();
+ cb.opc_swap();
+ cb.opc_invokespecial(invocationTargetCtorIdx, 1, 0);
+ cb.opc_athrow();
+
+ // Generate exception table. We cover the entire code sequence
+ // with an exception handler which catches ClassCastException and
+ // converts it into an IllegalArgumentException.
+
+ ClassFileAssembler exc = new ClassFileAssembler();
+
+ exc.emitShort(illegalArgStartPC); // start PC
+ exc.emitShort(invokeStartPC); // end PC
+ exc.emitShort(classCastHandler); // handler PC
+ exc.emitShort(classCastClass); // catch type
+
+ exc.emitShort(illegalArgStartPC); // start PC
+ exc.emitShort(invokeStartPC); // end PC
+ exc.emitShort(classCastHandler); // handler PC
+ exc.emitShort(nullPointerClass); // catch type
+
+ exc.emitShort(invokeStartPC); // start PC
+ exc.emitShort(invokeEndPC); // end PC
+ exc.emitShort(invocationTargetHandler); // handler PC
+ exc.emitShort(throwableClass); // catch type
+
+ emitMethod(invokeIdx, cb.getMaxLocals(), cb, exc,
+ new short[] { invocationTargetClass });
+ }
+
+ private boolean usesPrimitiveTypes() {
+ // We need to emit boxing/unboxing constant pool information if
+ // the method takes a primitive type for any of its parameters or
+ // returns a primitive value (except void)
+ if (returnType.isPrimitive()) {
+ return true;
+ }
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i].isPrimitive()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private int numNonPrimitiveParameterTypes() {
+ int num = 0;
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (!parameterTypes[i].isPrimitive()) {
+ ++num;
+ }
+ }
+ return num;
+ }
+
+ private boolean isInterface() {
+ return declaringClass.isInterface();
+ }
+
+ private String buildInternalSignature() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("(");
+ for (int i = 0; i < parameterTypes.length; i++) {
+ sb.append(getClassName(parameterTypes[i], true));
+ }
+ sb.append(")");
+ sb.append(getClassName(returnType, true));
+ return sb.toString();
+ }
+
+ private static synchronized String generateName(boolean isConstructor,
+ boolean forSerialization)
+ {
+ if (isConstructor) {
+ if (forSerialization) {
+ int num = ++serializationConstructorSymnum;
+ return "jdk/internal/reflect/GeneratedSerializationConstructorAccessor" + num;
+ } else {
+ int num = ++constructorSymnum;
+ return "jdk/internal/reflect/GeneratedConstructorAccessor" + num;
+ }
+ } else {
+ int num = ++methodSymnum;
+ return "jdk/internal/reflect/GeneratedMethodAccessor" + num;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/MethodAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.InvocationTargetException;
+
+/** <P> Package-private implementation of the MethodAccessor interface
+ which has access to all classes and all fields, regardless of
+ language restrictions. See MagicAccessor. </P>
+
+ <P> This class is known to the VM; do not change its name without
+ also changing the VM's code. </P>
+
+ <P> NOTE: ALL methods of subclasses are skipped during security
+ walks up the stack. The assumption is that the only such methods
+ that will persistently show up on the stack are the implementing
+ methods for java.lang.reflect.Method.invoke(). </P>
+*/
+
+abstract class MethodAccessorImpl extends MagicAccessorImpl
+ implements MethodAccessor {
+ /** Matches specification in {@link java.lang.reflect.Method} */
+ public abstract Object invoke(Object obj, Object[] args)
+ throws IllegalArgumentException, InvocationTargetException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/NativeConstructorAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,73 @@
+/*
+ * 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
+ * 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.
+ */
+
+package jdk.internal.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 */
+
+class NativeConstructorAccessorImpl extends ConstructorAccessorImpl {
+ private final Constructor<?> c;
+ private DelegatingConstructorAccessorImpl parent;
+ private int numInvocations;
+
+ NativeConstructorAccessorImpl(Constructor<?> c) {
+ this.c = c;
+ }
+
+ public Object newInstance(Object[] args)
+ throws InstantiationException,
+ IllegalArgumentException,
+ InvocationTargetException
+ {
+ // 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(),
+ c.getParameterTypes(),
+ c.getExceptionTypes(),
+ c.getModifiers());
+ parent.setDelegate(acc);
+ }
+
+ return newInstance0(c, args);
+ }
+
+ void setParent(DelegatingConstructorAccessorImpl parent) {
+ this.parent = parent;
+ }
+
+ private static native Object newInstance0(Constructor<?> c, Object[] args)
+ throws InstantiationException,
+ IllegalArgumentException,
+ InvocationTargetException;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/NativeMethodAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,70 @@
+/*
+ * 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
+ * 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.
+ */
+
+package jdk.internal.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 */
+
+class NativeMethodAccessorImpl extends MethodAccessorImpl {
+ private final Method method;
+ private DelegatingMethodAccessorImpl parent;
+ private int numInvocations;
+
+ NativeMethodAccessorImpl(Method method) {
+ this.method = method;
+ }
+
+ public Object invoke(Object obj, Object[] args)
+ throws IllegalArgumentException, InvocationTargetException
+ {
+ // 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(),
+ method.getName(),
+ method.getParameterTypes(),
+ method.getReturnType(),
+ method.getExceptionTypes(),
+ method.getModifiers());
+ parent.setDelegate(acc);
+ }
+
+ return invoke0(method, obj, args);
+ }
+
+ void setParent(DelegatingMethodAccessorImpl parent) {
+ this.parent = parent;
+ }
+
+ private static native Object invoke0(Method m, Object obj, Object[] args);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,425 @@
+/*
+ * 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
+ * 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.
+ */
+
+package jdk.internal.reflect;
+
+
+import java.lang.reflect.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import jdk.internal.HotSpotIntrinsicCandidate;
+import jdk.internal.misc.VM;
+
+/** Common utility routines used by both java.lang and
+ java.lang.reflect */
+
+public class Reflection {
+
+ /** Used to filter out fields and methods from certain classes from public
+ view, where they are sensitive or they may contain VM-internal objects.
+ These Maps are updated very rarely. Rather than synchronize on
+ each access, we use copy-on-write */
+ private static volatile Map<Class<?>,String[]> fieldFilterMap;
+ private static volatile Map<Class<?>,String[]> methodFilterMap;
+
+ static {
+ Map<Class<?>,String[]> map = new HashMap<Class<?>,String[]>();
+ map.put(Reflection.class,
+ new String[] {"fieldFilterMap", "methodFilterMap"});
+ map.put(System.class, new String[] {"security"});
+ map.put(Class.class, new String[] {"classLoader"});
+ fieldFilterMap = map;
+
+ methodFilterMap = new HashMap<>();
+ }
+
+ /** Returns the class of the caller of the method calling this method,
+ ignoring frames associated with java.lang.reflect.Method.invoke()
+ and its implementation. */
+ @CallerSensitive
+ @HotSpotIntrinsicCandidate
+ public static native Class<?> getCallerClass();
+
+ /**
+ * @deprecated This method will be removed.
+ * This method is a private JDK API and retained temporarily to
+ * simplify the implementation of sun.misc.Reflection.getCallerClass.
+ */
+ @Deprecated(forRemoval=true)
+ public static native Class<?> getCallerClass(int depth);
+
+ /** Retrieves the access flags written to the class file. For
+ inner classes these flags may differ from those returned by
+ Class.getModifiers(), which searches the InnerClasses
+ attribute to find the source-level access flags. This is used
+ instead of Class.getModifiers() for run-time access checks due
+ to compatibility reasons; see 4471811. Only the values of the
+ low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
+ valid. */
+ @HotSpotIntrinsicCandidate
+ public static native int getClassAccessFlags(Class<?> c);
+
+
+ public static void ensureMemberAccess(Class<?> currentClass,
+ Class<?> memberClass,
+ Object target,
+ int modifiers)
+ throws IllegalAccessException
+ {
+ if (currentClass == null || memberClass == null) {
+ throw new InternalError();
+ }
+
+ if (!verifyMemberAccess(currentClass, memberClass, target, modifiers)) {
+ throwIllegalAccessException(currentClass, memberClass, target, modifiers);
+ }
+ }
+
+ public static boolean verifyMemberAccess(Class<?> currentClass,
+ // Declaring class of field
+ // or method
+ Class<?> memberClass,
+ // May be NULL in case of statics
+ Object target,
+ int modifiers)
+ {
+ // Verify that currentClass can access a field, method, or
+ // constructor of memberClass, where that member's access bits are
+ // "modifiers".
+
+ boolean gotIsSameClassPackage = false;
+ boolean isSameClassPackage = false;
+
+ if (currentClass == memberClass) {
+ // Always succeeds
+ return true;
+ }
+
+ if (!verifyModuleAccess(currentClass, memberClass)) {
+ return false;
+ }
+
+ if (!Modifier.isPublic(getClassAccessFlags(memberClass))) {
+ isSameClassPackage = isSameClassPackage(currentClass, memberClass);
+ gotIsSameClassPackage = true;
+ if (!isSameClassPackage) {
+ return false;
+ }
+ }
+
+ // At this point we know that currentClass can access memberClass.
+
+ if (Modifier.isPublic(modifiers)) {
+ return true;
+ }
+
+ boolean successSoFar = false;
+
+ if (Modifier.isProtected(modifiers)) {
+ // See if currentClass is a subclass of memberClass
+ if (isSubclassOf(currentClass, memberClass)) {
+ successSoFar = true;
+ }
+ }
+
+ if (!successSoFar && !Modifier.isPrivate(modifiers)) {
+ if (!gotIsSameClassPackage) {
+ isSameClassPackage = isSameClassPackage(currentClass,
+ memberClass);
+ gotIsSameClassPackage = true;
+ }
+
+ if (isSameClassPackage) {
+ successSoFar = true;
+ }
+ }
+
+ if (!successSoFar) {
+ return false;
+ }
+
+ if (Modifier.isProtected(modifiers)) {
+ // Additional test for protected members: JLS 6.6.2
+ Class<?> targetClass = (target == null ? memberClass : target.getClass());
+ if (targetClass != currentClass) {
+ if (!gotIsSameClassPackage) {
+ isSameClassPackage = isSameClassPackage(currentClass, memberClass);
+ gotIsSameClassPackage = true;
+ }
+ if (!isSameClassPackage) {
+ if (!isSubclassOf(targetClass, currentClass)) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns {@code true} if memberClass's's module exports memberClass's
+ * package to currentClass's module.
+ */
+ public static boolean verifyModuleAccess(Class<?> currentClass,
+ Class<?> memberClass) {
+ return verifyModuleAccess(currentClass.getModule(), memberClass);
+ }
+
+ public static boolean verifyModuleAccess(Module currentModule, Class<?> memberClass) {
+ Module memberModule = memberClass.getModule();
+
+ // module may be null during startup (initLevel 0)
+ if (currentModule == memberModule)
+ return true; // same module (named or unnamed)
+
+ // memberClass may be primitive or array class
+ Class<?> c = memberClass;
+ while (c.isArray()) {
+ c = c.getComponentType();
+ }
+ if (c.isPrimitive())
+ return true;
+
+ // check that memberModule exports the package to currentModule
+ return memberModule.isExported(c.getPackageName(), currentModule);
+ }
+
+ /**
+ * Returns true if two classes in the same package.
+ */
+ private static boolean isSameClassPackage(Class<?> c1, Class<?> c2) {
+ if (c1.getClassLoader() != c2.getClassLoader())
+ return false;
+ while (c1.isArray())
+ c1 = c1.getComponentType();
+ while (c2.isArray())
+ c2 = c2.getComponentType();
+ return Objects.equals(c1.getPackageName(), c2.getPackageName());
+ }
+
+ static boolean isSubclassOf(Class<?> queryClass,
+ Class<?> ofClass)
+ {
+ while (queryClass != null) {
+ if (queryClass == ofClass) {
+ return true;
+ }
+ queryClass = queryClass.getSuperclass();
+ }
+ return false;
+ }
+
+ // fieldNames must contain only interned Strings
+ public static synchronized void registerFieldsToFilter(Class<?> containingClass,
+ String ... fieldNames) {
+ fieldFilterMap =
+ registerFilter(fieldFilterMap, containingClass, fieldNames);
+ }
+
+ // methodNames must contain only interned Strings
+ public static synchronized void registerMethodsToFilter(Class<?> containingClass,
+ String ... methodNames) {
+ methodFilterMap =
+ registerFilter(methodFilterMap, containingClass, methodNames);
+ }
+
+ private static Map<Class<?>,String[]> registerFilter(Map<Class<?>,String[]> map,
+ Class<?> containingClass, String ... names) {
+ if (map.get(containingClass) != null) {
+ throw new IllegalArgumentException
+ ("Filter already registered: " + containingClass);
+ }
+ map = new HashMap<Class<?>,String[]>(map);
+ map.put(containingClass, names);
+ return map;
+ }
+
+ public static Field[] filterFields(Class<?> containingClass,
+ Field[] fields) {
+ if (fieldFilterMap == null) {
+ // Bootstrapping
+ return fields;
+ }
+ return (Field[])filter(fields, fieldFilterMap.get(containingClass));
+ }
+
+ public static Method[] filterMethods(Class<?> containingClass, Method[] methods) {
+ if (methodFilterMap == null) {
+ // Bootstrapping
+ return methods;
+ }
+ return (Method[])filter(methods, methodFilterMap.get(containingClass));
+ }
+
+ private static Member[] filter(Member[] members, String[] filteredNames) {
+ if ((filteredNames == null) || (members.length == 0)) {
+ return members;
+ }
+ int numNewMembers = 0;
+ for (Member member : members) {
+ boolean shouldSkip = false;
+ for (String filteredName : filteredNames) {
+ if (member.getName() == filteredName) {
+ shouldSkip = true;
+ break;
+ }
+ }
+ if (!shouldSkip) {
+ ++numNewMembers;
+ }
+ }
+ Member[] newMembers =
+ (Member[])Array.newInstance(members[0].getClass(), numNewMembers);
+ int destIdx = 0;
+ for (Member member : members) {
+ boolean shouldSkip = false;
+ for (String filteredName : filteredNames) {
+ if (member.getName() == filteredName) {
+ shouldSkip = true;
+ break;
+ }
+ }
+ if (!shouldSkip) {
+ newMembers[destIdx++] = member;
+ }
+ }
+ return newMembers;
+ }
+
+ /**
+ * Tests if the given method is caller-sensitive and the declaring class
+ * is defined by either the bootstrap class loader or platform class loader.
+ */
+ public static boolean isCallerSensitive(Method m) {
+ final ClassLoader loader = m.getDeclaringClass().getClassLoader();
+ if (VM.isSystemDomainLoader(loader) || isExtClassLoader(loader)) {
+ return m.isAnnotationPresent(CallerSensitive.class);
+ }
+ return false;
+ }
+
+ private static boolean isExtClassLoader(ClassLoader loader) {
+ ClassLoader cl = ClassLoader.getSystemClassLoader();
+ while (cl != null) {
+ if (cl.getParent() == null && cl == loader) {
+ return true;
+ }
+ cl = cl.getParent();
+ }
+ return false;
+ }
+
+
+ // true to print a stack trace when IAE is thrown
+ private static volatile boolean printStackWhenAccessFails;
+
+ // true if printStackWhenAccessFails has been initialized
+ private static volatile boolean printStackWhenAccessFailsSet;
+
+ private static void printStackTraceIfNeeded(Throwable e) {
+ if (!printStackWhenAccessFailsSet && VM.initLevel() >= 1) {
+ // can't use method reference here, might be too early in startup
+ PrivilegedAction<Boolean> pa = new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ String s;
+ s = System.getProperty("sun.reflect.debugModuleAccessChecks");
+ return (s != null && !s.equalsIgnoreCase("false"));
+ }
+ };
+ printStackWhenAccessFails = AccessController.doPrivileged(pa);
+ printStackWhenAccessFailsSet = true;
+ }
+ if (printStackWhenAccessFails) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Throws IllegalAccessException with the an exception message based on
+ * the access that is denied.
+ */
+ private static void throwIllegalAccessException(Class<?> currentClass,
+ Class<?> memberClass,
+ Object target,
+ int modifiers)
+ throws IllegalAccessException
+ {
+ String currentSuffix = "";
+ String memberSuffix = "";
+ Module m1 = currentClass.getModule();
+ if (m1.isNamed())
+ currentSuffix = " (in " + m1 + ")";
+ Module m2 = memberClass.getModule();
+ if (m2.isNamed())
+ memberSuffix = " (in " + m2 + ")";
+
+ Class<?> c = memberClass;
+ while (c.isArray()) {
+ c = c.getComponentType();
+ }
+ String memberPackageName = c.getPackageName();
+
+ String msg = currentClass + currentSuffix + " cannot access ";
+ if (m2.isExported(memberPackageName, m1)) {
+
+ // module access okay so include the modifiers in the message
+ msg += "a member of " + memberClass + memberSuffix +
+ " with modifiers \"" + Modifier.toString(modifiers) + "\"";
+
+ } else {
+ // module access failed
+ msg += memberClass + memberSuffix+ " because "
+ + m2 + " does not export " + memberPackageName;
+ if (m2.isNamed()) msg += " to " + m1;
+ }
+
+ throwIllegalAccessException(msg);
+ }
+
+ /**
+ * Throws IllegalAccessException with the given exception message.
+ */
+ public static void throwIllegalAccessException(String msg)
+ throws IllegalAccessException
+ {
+ IllegalAccessException e = new IllegalAccessException(msg);
+ printStackTraceIfNeeded(e);
+ throw e;
+ }
+
+ /**
+ * Throws InaccessibleObjectException with the given exception message.
+ */
+ public static void throwInaccessibleObjectException(String msg) {
+ InaccessibleObjectException e = new InaccessibleObjectException(msg);
+ printStackTraceIfNeeded(e);
+ throw e;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,432 @@
+/*
+ * 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
+ * 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Executable;
+import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.PrivilegedAction;
+import sun.reflect.misc.ReflectUtil;
+
+/** <P> The master factory for all reflective objects, both those in
+ java.lang.reflect (Fields, Methods, Constructors) as well as their
+ delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
+ </P>
+
+ <P> The methods in this class are extremely unsafe and can cause
+ subversion of both the language and the verifier. For this reason,
+ they are all instance methods, and access to the constructor of
+ this factory is guarded by a security check, in similar style to
+ {@link jdk.internal.misc.Unsafe}. </P>
+*/
+
+public class ReflectionFactory {
+
+ private static boolean initted = false;
+ private static final Permission reflectionFactoryAccessPerm
+ = new RuntimePermission("reflectionFactoryAccess");
+ private static final ReflectionFactory soleInstance = new ReflectionFactory();
+ // Provides access to package-private mechanisms in java.lang.reflect
+ private static volatile LangReflectAccess langReflectAccess;
+
+ //
+ // "Inflation" mechanism. Loading bytecodes to implement
+ // Method.invoke() and Constructor.newInstance() currently costs
+ // 3-4x more than an invocation via native code for the first
+ // invocation (though subsequent invocations have been benchmarked
+ // to be over 20x faster). Unfortunately this cost increases
+ // startup time for certain applications that use reflection
+ // intensively (but only once per class) to bootstrap themselves.
+ // To avoid this penalty we reuse the existing JVM entry points
+ // for the first few invocations of Methods and Constructors and
+ // then switch to the bytecode-based implementations.
+ //
+ // Package-private to be accessible to NativeMethodAccessorImpl
+ // and NativeConstructorAccessorImpl
+ private static boolean noInflation = false;
+ private static int inflationThreshold = 15;
+
+ private ReflectionFactory() {
+ }
+
+ /**
+ * A convenience class for acquiring the capability to instantiate
+ * reflective objects. Use this instead of a raw call to {@link
+ * #getReflectionFactory} in order to avoid being limited by the
+ * permissions of your callers.
+ *
+ * <p>An instance of this class can be used as the argument of
+ * <code>AccessController.doPrivileged</code>.
+ */
+ public static final class GetReflectionFactoryAction
+ implements PrivilegedAction<ReflectionFactory> {
+ public ReflectionFactory run() {
+ return getReflectionFactory();
+ }
+ }
+
+ /**
+ * Provides the caller with the capability to instantiate reflective
+ * objects.
+ *
+ * <p> First, if there is a security manager, its
+ * <code>checkPermission</code> method is called with a {@link
+ * java.lang.RuntimePermission} with target
+ * <code>"reflectionFactoryAccess"</code>. This may result in a
+ * security exception.
+ *
+ * <p> The returned <code>ReflectionFactory</code> object should be
+ * carefully guarded by the caller, since it can be used to read and
+ * write private data and invoke private methods, as well as to load
+ * unverified bytecodes. It must never be passed to untrusted code.
+ *
+ * @exception SecurityException if a security manager exists and its
+ * <code>checkPermission</code> method doesn't allow
+ * access to the RuntimePermission "reflectionFactoryAccess". */
+ public static ReflectionFactory getReflectionFactory() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ // TO DO: security.checkReflectionFactoryAccess();
+ security.checkPermission(reflectionFactoryAccessPerm);
+ }
+ return soleInstance;
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Routines used by java.lang.reflect
+ //
+ //
+
+ /** Called only by java.lang.reflect.Modifier's static initializer */
+ public void setLangReflectAccess(LangReflectAccess access) {
+ langReflectAccess = access;
+ }
+
+ /**
+ * Note: this routine can cause the declaring class for the field
+ * be initialized and therefore must not be called until the
+ * first get/set of this field.
+ * @param field the field
+ * @param override true if caller has overridden accessibility
+ */
+ public FieldAccessor newFieldAccessor(Field field, boolean override) {
+ checkInitted();
+ return UnsafeFieldAccessorFactory.newFieldAccessor(field, override);
+ }
+
+ public MethodAccessor newMethodAccessor(Method method) {
+ checkInitted();
+
+ if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
+ return new MethodAccessorGenerator().
+ generateMethod(method.getDeclaringClass(),
+ method.getName(),
+ method.getParameterTypes(),
+ method.getReturnType(),
+ method.getExceptionTypes(),
+ method.getModifiers());
+ } else {
+ NativeMethodAccessorImpl acc =
+ new NativeMethodAccessorImpl(method);
+ DelegatingMethodAccessorImpl res =
+ new DelegatingMethodAccessorImpl(acc);
+ acc.setParent(res);
+ return res;
+ }
+ }
+
+ public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
+ checkInitted();
+
+ Class<?> declaringClass = c.getDeclaringClass();
+ if (Modifier.isAbstract(declaringClass.getModifiers())) {
+ return new InstantiationExceptionConstructorAccessorImpl(null);
+ }
+ if (declaringClass == Class.class) {
+ return new InstantiationExceptionConstructorAccessorImpl
+ ("Can not instantiate java.lang.Class");
+ }
+ // Bootstrapping issue: since we use Class.newInstance() in
+ // the ConstructorAccessor generation process, we have to
+ // break the cycle here.
+ if (Reflection.isSubclassOf(declaringClass,
+ ConstructorAccessorImpl.class)) {
+ return new BootstrapConstructorAccessorImpl(c);
+ }
+
+ if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
+ return new MethodAccessorGenerator().
+ generateConstructor(c.getDeclaringClass(),
+ c.getParameterTypes(),
+ c.getExceptionTypes(),
+ c.getModifiers());
+ } else {
+ NativeConstructorAccessorImpl acc =
+ new NativeConstructorAccessorImpl(c);
+ DelegatingConstructorAccessorImpl res =
+ new DelegatingConstructorAccessorImpl(acc);
+ acc.setParent(res);
+ return res;
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Routines used by java.lang
+ //
+ //
+
+ /** Creates a new java.lang.reflect.Field. Access checks as per
+ java.lang.reflect.AccessibleObject are not overridden. */
+ public Field newField(Class<?> declaringClass,
+ String name,
+ Class<?> type,
+ int modifiers,
+ int slot,
+ String signature,
+ byte[] annotations)
+ {
+ return langReflectAccess().newField(declaringClass,
+ name,
+ type,
+ modifiers,
+ slot,
+ signature,
+ annotations);
+ }
+
+ /** Creates a new java.lang.reflect.Method. Access checks as per
+ java.lang.reflect.AccessibleObject are not overridden. */
+ public Method newMethod(Class<?> declaringClass,
+ String name,
+ Class<?>[] parameterTypes,
+ Class<?> returnType,
+ Class<?>[] checkedExceptions,
+ int modifiers,
+ int slot,
+ String signature,
+ byte[] annotations,
+ byte[] parameterAnnotations,
+ byte[] annotationDefault)
+ {
+ return langReflectAccess().newMethod(declaringClass,
+ name,
+ parameterTypes,
+ returnType,
+ checkedExceptions,
+ modifiers,
+ slot,
+ signature,
+ annotations,
+ parameterAnnotations,
+ annotationDefault);
+ }
+
+ /** Creates a new java.lang.reflect.Constructor. Access checks as
+ per java.lang.reflect.AccessibleObject are not overridden. */
+ public Constructor<?> newConstructor(Class<?> declaringClass,
+ Class<?>[] parameterTypes,
+ Class<?>[] checkedExceptions,
+ int modifiers,
+ int slot,
+ String signature,
+ byte[] annotations,
+ byte[] parameterAnnotations)
+ {
+ return langReflectAccess().newConstructor(declaringClass,
+ parameterTypes,
+ checkedExceptions,
+ modifiers,
+ slot,
+ signature,
+ annotations,
+ parameterAnnotations);
+ }
+
+ /** Gets the MethodAccessor object for a java.lang.reflect.Method */
+ public MethodAccessor getMethodAccessor(Method m) {
+ return langReflectAccess().getMethodAccessor(m);
+ }
+
+ /** Sets the MethodAccessor object for a java.lang.reflect.Method */
+ public void setMethodAccessor(Method m, MethodAccessor accessor) {
+ langReflectAccess().setMethodAccessor(m, accessor);
+ }
+
+ /** Gets the ConstructorAccessor object for a
+ java.lang.reflect.Constructor */
+ public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
+ return langReflectAccess().getConstructorAccessor(c);
+ }
+
+ /** Sets the ConstructorAccessor object for a
+ java.lang.reflect.Constructor */
+ public void setConstructorAccessor(Constructor<?> c,
+ ConstructorAccessor accessor)
+ {
+ langReflectAccess().setConstructorAccessor(c, accessor);
+ }
+
+ /** Makes a copy of the passed method. The returned method is a
+ "child" of the passed one; see the comments in Method.java for
+ details. */
+ public Method copyMethod(Method arg) {
+ return langReflectAccess().copyMethod(arg);
+ }
+
+ /** Makes a copy of the passed method. The returned method is NOT
+ * a "child" but a "sibling" of the Method in arg. Should only be
+ * used on non-root methods. */
+ public Method leafCopyMethod(Method arg) {
+ return langReflectAccess().leafCopyMethod(arg);
+ }
+
+
+ /** Makes a copy of the passed field. The returned field is a
+ "child" of the passed one; see the comments in Field.java for
+ details. */
+ public Field copyField(Field arg) {
+ return langReflectAccess().copyField(arg);
+ }
+
+ /** Makes a copy of the passed constructor. The returned
+ constructor is a "child" of the passed one; see the comments
+ in Constructor.java for details. */
+ public <T> Constructor<T> copyConstructor(Constructor<T> arg) {
+ return langReflectAccess().copyConstructor(arg);
+ }
+
+ /** Gets the byte[] that encodes TypeAnnotations on an executable.
+ */
+ public byte[] getExecutableTypeAnnotationBytes(Executable ex) {
+ return langReflectAccess().getExecutableTypeAnnotationBytes(ex);
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Routines used by serialization
+ //
+ //
+
+ public Constructor<?> newConstructorForSerialization
+ (Class<?> classToInstantiate, Constructor<?> constructorToCall)
+ {
+ // Fast path
+ if (constructorToCall.getDeclaringClass() == classToInstantiate) {
+ return constructorToCall;
+ }
+
+ ConstructorAccessor acc = new MethodAccessorGenerator().
+ generateSerializationConstructor(classToInstantiate,
+ constructorToCall.getParameterTypes(),
+ constructorToCall.getExceptionTypes(),
+ constructorToCall.getModifiers(),
+ constructorToCall.getDeclaringClass());
+ Constructor<?> c = newConstructor(constructorToCall.getDeclaringClass(),
+ constructorToCall.getParameterTypes(),
+ constructorToCall.getExceptionTypes(),
+ constructorToCall.getModifiers(),
+ langReflectAccess().
+ getConstructorSlot(constructorToCall),
+ langReflectAccess().
+ getConstructorSignature(constructorToCall),
+ langReflectAccess().
+ getConstructorAnnotations(constructorToCall),
+ langReflectAccess().
+ getConstructorParameterAnnotations(constructorToCall));
+ setConstructorAccessor(c, acc);
+ return c;
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Internals only below this point
+ //
+
+ static int inflationThreshold() {
+ return inflationThreshold;
+ }
+
+ /** We have to defer full initialization of this class until after
+ the static initializer is run since java.lang.reflect.Method's
+ static initializer (more properly, that for
+ java.lang.reflect.AccessibleObject) causes this class's to be
+ run, before the system properties are set up. */
+ private static void checkInitted() {
+ if (initted) return;
+ AccessController.doPrivileged(
+ new PrivilegedAction<>() {
+ public Void run() {
+ // Tests to ensure the system properties table is fully
+ // initialized. This is needed because reflection code is
+ // called very early in the initialization process (before
+ // command-line arguments have been parsed and therefore
+ // these user-settable properties installed.) We assume that
+ // if System.out is non-null then the System class has been
+ // fully initialized and that the bulk of the startup code
+ // has been run.
+
+ if (System.out == null) {
+ // java.lang.System not yet fully initialized
+ return null;
+ }
+
+ String val = System.getProperty("sun.reflect.noInflation");
+ if (val != null && val.equals("true")) {
+ noInflation = true;
+ }
+
+ val = System.getProperty("sun.reflect.inflationThreshold");
+ if (val != null) {
+ try {
+ inflationThreshold = Integer.parseInt(val);
+ } catch (NumberFormatException e) {
+ throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e);
+ }
+ }
+
+ initted = true;
+ return null;
+ }
+ });
+ }
+
+ private static LangReflectAccess langReflectAccess() {
+ if (langReflectAccess == null) {
+ // Call a static method to get class java.lang.reflect.Modifier
+ // initialized. Its static initializer will cause
+ // setLangReflectAccess() to be called from the context of the
+ // java.lang.reflect package.
+ Modifier.isPublic(Modifier.PUBLIC);
+ }
+ return langReflectAccess;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/SerializationConstructorAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** <P> Java serialization (in java.io) expects to be able to
+ instantiate a class and invoke a no-arg constructor of that
+ class's first non-Serializable superclass. This is not a valid
+ operation according to the VM specification; one can not (for
+ classes A and B, where B is a subclass of A) write "new B;
+ invokespecial A()" without getting a verification error. </P>
+
+ <P> In all other respects, the bytecode-based reflection framework
+ can be reused for this purpose. This marker class was originally
+ known to the VM and verification disabled for it and all
+ subclasses, but the bug fix for 4486457 necessitated disabling
+ verification for all of the dynamically-generated bytecodes
+ associated with reflection. This class has been left in place to
+ make future debugging easier. </P> */
+
+abstract class SerializationConstructorAccessorImpl
+ extends ConstructorAccessorImpl {
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/SignatureIterator.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2001, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** Assists in iterating down a method's signature */
+
+class SignatureIterator {
+ private final String sig;
+ private int idx;
+
+ public SignatureIterator(String sig) {
+ this.sig = sig;
+ reset();
+ }
+
+ public void reset() {
+ idx = 1;
+ }
+
+ public boolean atEnd() {
+ return sig.charAt(idx) == ')';
+ }
+
+ public String next() {
+ if (atEnd()) return null;
+ char c = sig.charAt(idx);
+ if (c != '[' && c != 'L') {
+ ++idx;
+ return new String(new char[] { c });
+ }
+ // Walk forward to end of entry
+ int endIdx = idx;
+ if (c == '[') {
+ while ((c = sig.charAt(endIdx)) == '[') {
+ endIdx++;
+ }
+ }
+
+ if (c == 'L') {
+ while (sig.charAt(endIdx) != ';') {
+ endIdx++;
+ }
+ }
+
+ int beginIdx = idx;
+ idx = endIdx + 1;
+ return sig.substring(beginIdx, idx);
+ }
+
+ /** Should only be called when atEnd() is true. Does not change
+ state of iterator. */
+ public String returnType() {
+ if (!atEnd()) {
+ throw new InternalError("Illegal use of SignatureIterator");
+ }
+ return sig.substring(idx + 1, sig.length());
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UTF8.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2001, 2011, 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.
+ */
+
+package jdk.internal.reflect;
+
+/** It is necessary to use a "bootstrap" UTF-8 encoder for encoding
+ constant pool entries because the character set converters rely on
+ Class.newInstance(). */
+
+class UTF8 {
+ // This encoder is not quite correct. It does not handle surrogate pairs.
+ static byte[] encode(String str) {
+ int len = str.length();
+ byte[] res = new byte[utf8Length(str)];
+ int utf8Idx = 0;
+ try {
+ for (int i = 0; i < len; i++) {
+ int c = str.charAt(i) & 0xFFFF;
+ if (c >= 0x0001 && c <= 0x007F) {
+ res[utf8Idx++] = (byte) c;
+ } else if (c == 0x0000 ||
+ (c >= 0x0080 && c <= 0x07FF)) {
+ res[utf8Idx++] = (byte) (0xC0 + (c >> 6));
+ res[utf8Idx++] = (byte) (0x80 + (c & 0x3F));
+ } else {
+ res[utf8Idx++] = (byte) (0xE0 + (c >> 12));
+ res[utf8Idx++] = (byte) (0x80 + ((c >> 6) & 0x3F));
+ res[utf8Idx++] = (byte) (0x80 + (c & 0x3F));
+ }
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new InternalError
+ ("Bug in sun.reflect bootstrap UTF-8 encoder", e);
+ }
+ return res;
+ }
+
+ private static int utf8Length(String str) {
+ int len = str.length();
+ int utf8Len = 0;
+ for (int i = 0; i < len; i++) {
+ int c = str.charAt(i) & 0xFFFF;
+ if (c >= 0x0001 && c <= 0x007F) {
+ utf8Len += 1;
+ } else if (c == 0x0000 ||
+ (c >= 0x0080 && c <= 0x07FF)) {
+ utf8Len += 2;
+ } else {
+ utf8Len += 3;
+ }
+ }
+ return utf8Len;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeBooleanFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeBooleanFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeBooleanFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Boolean.valueOf(getBoolean(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getBoolean(obj, fieldOffset);
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Boolean) {
+ unsafe.putBoolean(obj, fieldOffset, ((Boolean) value).booleanValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(z);
+ }
+ unsafe.putBoolean(obj, fieldOffset, z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeByteFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeByteFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeByteFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Byte.valueOf(getByte(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getByte(obj, fieldOffset);
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putByte(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(b);
+ }
+ unsafe.putByte(obj, fieldOffset, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeCharacterFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeCharacterFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeCharacterFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Character.valueOf(getChar(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getChar(obj, fieldOffset);
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Character) {
+ unsafe.putChar(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(c);
+ }
+ unsafe.putChar(obj, fieldOffset, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeDoubleFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeDoubleFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeDoubleFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Double.valueOf(getDouble(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getDouble(obj, fieldOffset);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putDouble(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putDouble(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putDouble(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putDouble(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putDouble(obj, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putDouble(obj, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ if (value instanceof Double) {
+ unsafe.putDouble(obj, fieldOffset, ((Double) value).doubleValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(d);
+ }
+ unsafe.putDouble(obj, fieldOffset, d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeFieldAccessorFactory.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2001, 2011, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+class UnsafeFieldAccessorFactory {
+ static FieldAccessor newFieldAccessor(Field field, boolean override) {
+ Class<?> type = field.getType();
+ boolean isStatic = Modifier.isStatic(field.getModifiers());
+ boolean isFinal = Modifier.isFinal(field.getModifiers());
+ boolean isVolatile = Modifier.isVolatile(field.getModifiers());
+ boolean isQualified = isFinal || isVolatile;
+ boolean isReadOnly = isFinal && (isStatic || !override);
+ if (isStatic) {
+ // This code path does not guarantee that the field's
+ // declaring class has been initialized, but it must be
+ // before performing reflective operations.
+ UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());
+
+ if (!isQualified) {
+ if (type == Boolean.TYPE) {
+ return new UnsafeStaticBooleanFieldAccessorImpl(field);
+ } else if (type == Byte.TYPE) {
+ return new UnsafeStaticByteFieldAccessorImpl(field);
+ } else if (type == Short.TYPE) {
+ return new UnsafeStaticShortFieldAccessorImpl(field);
+ } else if (type == Character.TYPE) {
+ return new UnsafeStaticCharacterFieldAccessorImpl(field);
+ } else if (type == Integer.TYPE) {
+ return new UnsafeStaticIntegerFieldAccessorImpl(field);
+ } else if (type == Long.TYPE) {
+ return new UnsafeStaticLongFieldAccessorImpl(field);
+ } else if (type == Float.TYPE) {
+ return new UnsafeStaticFloatFieldAccessorImpl(field);
+ } else if (type == Double.TYPE) {
+ return new UnsafeStaticDoubleFieldAccessorImpl(field);
+ } else {
+ return new UnsafeStaticObjectFieldAccessorImpl(field);
+ }
+ } else {
+ if (type == Boolean.TYPE) {
+ return new UnsafeQualifiedStaticBooleanFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Byte.TYPE) {
+ return new UnsafeQualifiedStaticByteFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Short.TYPE) {
+ return new UnsafeQualifiedStaticShortFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Character.TYPE) {
+ return new UnsafeQualifiedStaticCharacterFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Integer.TYPE) {
+ return new UnsafeQualifiedStaticIntegerFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Long.TYPE) {
+ return new UnsafeQualifiedStaticLongFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Float.TYPE) {
+ return new UnsafeQualifiedStaticFloatFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Double.TYPE) {
+ return new UnsafeQualifiedStaticDoubleFieldAccessorImpl(field, isReadOnly);
+ } else {
+ return new UnsafeQualifiedStaticObjectFieldAccessorImpl(field, isReadOnly);
+ }
+ }
+ } else {
+ if (!isQualified) {
+ if (type == Boolean.TYPE) {
+ return new UnsafeBooleanFieldAccessorImpl(field);
+ } else if (type == Byte.TYPE) {
+ return new UnsafeByteFieldAccessorImpl(field);
+ } else if (type == Short.TYPE) {
+ return new UnsafeShortFieldAccessorImpl(field);
+ } else if (type == Character.TYPE) {
+ return new UnsafeCharacterFieldAccessorImpl(field);
+ } else if (type == Integer.TYPE) {
+ return new UnsafeIntegerFieldAccessorImpl(field);
+ } else if (type == Long.TYPE) {
+ return new UnsafeLongFieldAccessorImpl(field);
+ } else if (type == Float.TYPE) {
+ return new UnsafeFloatFieldAccessorImpl(field);
+ } else if (type == Double.TYPE) {
+ return new UnsafeDoubleFieldAccessorImpl(field);
+ } else {
+ return new UnsafeObjectFieldAccessorImpl(field);
+ }
+ } else {
+ if (type == Boolean.TYPE) {
+ return new UnsafeQualifiedBooleanFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Byte.TYPE) {
+ return new UnsafeQualifiedByteFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Short.TYPE) {
+ return new UnsafeQualifiedShortFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Character.TYPE) {
+ return new UnsafeQualifiedCharacterFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Integer.TYPE) {
+ return new UnsafeQualifiedIntegerFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Long.TYPE) {
+ return new UnsafeQualifiedLongFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Float.TYPE) {
+ return new UnsafeQualifiedFloatFieldAccessorImpl(field, isReadOnly);
+ } else if (type == Double.TYPE) {
+ return new UnsafeQualifiedDoubleFieldAccessorImpl(field, isReadOnly);
+ } else {
+ return new UnsafeQualifiedObjectFieldAccessorImpl(field, isReadOnly);
+ }
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2001, 2011, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import jdk.internal.misc.Unsafe;
+
+/** Base class for jdk.internal.misc.Unsafe-based FieldAccessors. The
+ observation is that there are only nine types of fields from the
+ standpoint of reflection code: the eight primitive types and
+ Object. Using class Unsafe instead of generated bytecodes saves
+ memory and loading time for the dynamically-generated
+ FieldAccessors. */
+
+abstract class UnsafeFieldAccessorImpl extends FieldAccessorImpl {
+ static final Unsafe unsafe = Unsafe.getUnsafe();
+
+ protected final Field field;
+ protected final long fieldOffset;
+ protected final boolean isFinal;
+
+ UnsafeFieldAccessorImpl(Field field) {
+ this.field = field;
+ if (Modifier.isStatic(field.getModifiers()))
+ fieldOffset = unsafe.staticFieldOffset(field);
+ else
+ fieldOffset = unsafe.objectFieldOffset(field);
+ isFinal = Modifier.isFinal(field.getModifiers());
+ }
+
+ protected void ensureObj(Object o) {
+ // NOTE: will throw NullPointerException, as specified, if o is null
+ if (!field.getDeclaringClass().isAssignableFrom(o.getClass())) {
+ throwSetIllegalArgumentException(o);
+ }
+ }
+
+ private String getQualifiedFieldName() {
+ return field.getDeclaringClass().getName() + "." +field.getName();
+ }
+
+ protected IllegalArgumentException newGetIllegalArgumentException(String type) {
+ return new IllegalArgumentException(
+ "Attempt to get "+field.getType().getName()+" field \"" +
+ getQualifiedFieldName() + "\" with illegal data type conversion to "+type
+ );
+ }
+
+ protected void throwFinalFieldIllegalAccessException(String attemptedType,
+ String attemptedValue)
+ throws IllegalAccessException {
+ throw new IllegalAccessException(getSetMessage(attemptedType, attemptedValue));
+
+ }
+ protected void throwFinalFieldIllegalAccessException(Object o) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException(o != null ? o.getClass().getName() : "", "");
+ }
+
+ protected void throwFinalFieldIllegalAccessException(boolean z) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("boolean", Boolean.toString(z));
+ }
+
+ protected void throwFinalFieldIllegalAccessException(char b) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("char", Character.toString(b));
+ }
+
+ protected void throwFinalFieldIllegalAccessException(byte b) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("byte", Byte.toString(b));
+ }
+
+ protected void throwFinalFieldIllegalAccessException(short b) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("short", Short.toString(b));
+ }
+
+ protected void throwFinalFieldIllegalAccessException(int i) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("int", Integer.toString(i));
+ }
+
+ protected void throwFinalFieldIllegalAccessException(long i) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("long", Long.toString(i));
+ }
+
+ protected void throwFinalFieldIllegalAccessException(float f) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("float", Float.toString(f));
+ }
+
+ protected void throwFinalFieldIllegalAccessException(double f) throws IllegalAccessException {
+ throwFinalFieldIllegalAccessException("double", Double.toString(f));
+ }
+
+ protected IllegalArgumentException newGetBooleanIllegalArgumentException() {
+ return newGetIllegalArgumentException("boolean");
+ }
+
+ protected IllegalArgumentException newGetByteIllegalArgumentException() {
+ return newGetIllegalArgumentException("byte");
+ }
+
+ protected IllegalArgumentException newGetCharIllegalArgumentException() {
+ return newGetIllegalArgumentException("char");
+ }
+
+ protected IllegalArgumentException newGetShortIllegalArgumentException() {
+ return newGetIllegalArgumentException("short");
+ }
+
+ protected IllegalArgumentException newGetIntIllegalArgumentException() {
+ return newGetIllegalArgumentException("int");
+ }
+
+ protected IllegalArgumentException newGetLongIllegalArgumentException() {
+ return newGetIllegalArgumentException("long");
+ }
+
+ protected IllegalArgumentException newGetFloatIllegalArgumentException() {
+ return newGetIllegalArgumentException("float");
+ }
+
+ protected IllegalArgumentException newGetDoubleIllegalArgumentException() {
+ return newGetIllegalArgumentException("double");
+ }
+
+ protected String getSetMessage(String attemptedType, String attemptedValue) {
+ String err = "Can not set";
+ if (Modifier.isStatic(field.getModifiers()))
+ err += " static";
+ if (isFinal)
+ err += " final";
+ err += " " + field.getType().getName() + " field " + getQualifiedFieldName() + " to ";
+ if (attemptedValue.length() > 0) {
+ err += "(" + attemptedType + ")" + attemptedValue;
+ } else {
+ if (attemptedType.length() > 0)
+ err += attemptedType;
+ else
+ err += "null value";
+ }
+ return err;
+ }
+
+ protected void throwSetIllegalArgumentException(String attemptedType,
+ String attemptedValue) {
+ throw new IllegalArgumentException(getSetMessage(attemptedType,attemptedValue));
+ }
+
+ protected void throwSetIllegalArgumentException(Object o) {
+ throwSetIllegalArgumentException(o != null ? o.getClass().getName() : "", "");
+ }
+
+ protected void throwSetIllegalArgumentException(boolean b) {
+ throwSetIllegalArgumentException("boolean", Boolean.toString(b));
+ }
+
+ protected void throwSetIllegalArgumentException(byte b) {
+ throwSetIllegalArgumentException("byte", Byte.toString(b));
+ }
+
+ protected void throwSetIllegalArgumentException(char c) {
+ throwSetIllegalArgumentException("char", Character.toString(c));
+ }
+
+ protected void throwSetIllegalArgumentException(short s) {
+ throwSetIllegalArgumentException("short", Short.toString(s));
+ }
+
+ protected void throwSetIllegalArgumentException(int i) {
+ throwSetIllegalArgumentException("int", Integer.toString(i));
+ }
+
+ protected void throwSetIllegalArgumentException(long l) {
+ throwSetIllegalArgumentException("long", Long.toString(l));
+ }
+
+ protected void throwSetIllegalArgumentException(float f) {
+ throwSetIllegalArgumentException("float", Float.toString(f));
+ }
+
+ protected void throwSetIllegalArgumentException(double d) {
+ throwSetIllegalArgumentException("double", Double.toString(d));
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeFloatFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeFloatFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeFloatFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Float.valueOf(getFloat(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getFloat(obj, fieldOffset);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getFloat(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putFloat(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putFloat(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putFloat(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putFloat(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putFloat(obj, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putFloat(obj, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(f);
+ }
+ unsafe.putFloat(obj, fieldOffset, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeIntegerFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeIntegerFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeIntegerFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Integer.valueOf(getInt(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getInt(obj, fieldOffset);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putInt(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putInt(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putInt(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putInt(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(i);
+ }
+ unsafe.putInt(obj, fieldOffset, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeLongFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeLongFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeLongFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Long.valueOf(getLong(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getLong(obj, fieldOffset);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putLong(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putLong(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putLong(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putLong(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putLong(obj, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(l);
+ }
+ unsafe.putLong(obj, fieldOffset, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeObjectFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeObjectFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeObjectFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getObject(obj, fieldOffset);
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value != null) {
+ if (!field.getType().isAssignableFrom(value.getClass())) {
+ throwSetIllegalArgumentException(value);
+ }
+ }
+ unsafe.putObject(obj, fieldOffset, value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedBooleanFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedBooleanFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedBooleanFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Boolean.valueOf(getBoolean(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getBooleanVolatile(obj, fieldOffset);
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Boolean) {
+ unsafe.putBooleanVolatile(obj, fieldOffset, ((Boolean) value).booleanValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(z);
+ }
+ unsafe.putBooleanVolatile(obj, fieldOffset, z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedByteFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedByteFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedByteFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Byte.valueOf(getByte(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getByteVolatile(obj, fieldOffset);
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putByteVolatile(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(b);
+ }
+ unsafe.putByteVolatile(obj, fieldOffset, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedCharacterFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedCharacterFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedCharacterFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Character.valueOf(getChar(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getCharVolatile(obj, fieldOffset);
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Character) {
+ unsafe.putCharVolatile(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(c);
+ }
+ unsafe.putCharVolatile(obj, fieldOffset, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedDoubleFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedDoubleFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedDoubleFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Double.valueOf(getDouble(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getDoubleVolatile(obj, fieldOffset);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putDoubleVolatile(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putDoubleVolatile(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putDoubleVolatile(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putDoubleVolatile(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putDoubleVolatile(obj, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putDoubleVolatile(obj, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ if (value instanceof Double) {
+ unsafe.putDoubleVolatile(obj, fieldOffset, ((Double) value).doubleValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(d);
+ }
+ unsafe.putDoubleVolatile(obj, fieldOffset, d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2004, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import jdk.internal.misc.Unsafe;
+
+/**
+ * Base class for jdk.internal.misc.Unsafe-based FieldAccessors for fields with
+ * final or volatile qualifiers. These differ from unqualified
+ * versions in that (1) they check for read-only status (2) they use
+ * the volatile forms of Unsafe get/put methods. (When accessed via
+ * reflection, finals act as slightly "lighter" forms of volatiles. So
+ * the volatile forms are heavier than necessary in terms of
+ * underlying reordering rules and memory barriers, but preserve
+ * correctness.)
+ */
+
+abstract class UnsafeQualifiedFieldAccessorImpl
+ extends UnsafeFieldAccessorImpl
+{
+ protected final boolean isReadOnly;
+
+ UnsafeQualifiedFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field);
+ this.isReadOnly = isReadOnly;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedFloatFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedFloatFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedFloatFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Float.valueOf(getFloat(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getFloatVolatile(obj, fieldOffset);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getFloat(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putFloatVolatile(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putFloatVolatile(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putFloatVolatile(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putFloatVolatile(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putFloatVolatile(obj, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putFloatVolatile(obj, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(f);
+ }
+ unsafe.putFloatVolatile(obj, fieldOffset, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedIntegerFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedIntegerFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedIntegerFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Integer.valueOf(getInt(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getIntVolatile(obj, fieldOffset);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putIntVolatile(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putIntVolatile(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putIntVolatile(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putIntVolatile(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(i);
+ }
+ unsafe.putIntVolatile(obj, fieldOffset, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedLongFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedLongFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedLongFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Long.valueOf(getLong(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getLongVolatile(obj, fieldOffset);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putLongVolatile(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putLongVolatile(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putLongVolatile(obj, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putLongVolatile(obj, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putLongVolatile(obj, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(l);
+ }
+ unsafe.putLongVolatile(obj, fieldOffset, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedObjectFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedObjectFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedObjectFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getObjectVolatile(obj, fieldOffset);
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value != null) {
+ if (!field.getType().isAssignableFrom(value.getClass())) {
+ throwSetIllegalArgumentException(value);
+ }
+ }
+ unsafe.putObjectVolatile(obj, fieldOffset, value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedShortFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedShortFieldAccessorImpl
+ extends UnsafeQualifiedFieldAccessorImpl
+{
+ UnsafeQualifiedShortFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Short.valueOf(getShort(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getShortVolatile(obj, fieldOffset);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putShortVolatile(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putShortVolatile(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setShort(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(s);
+ }
+ unsafe.putShortVolatile(obj, fieldOffset, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticBooleanFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticBooleanFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticBooleanFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Boolean.valueOf(getBoolean(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ return unsafe.getBooleanVolatile(base, fieldOffset);
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Boolean) {
+ unsafe.putBooleanVolatile(base, fieldOffset, ((Boolean) value).booleanValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(z);
+ }
+ unsafe.putBooleanVolatile(base, fieldOffset, z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticByteFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticByteFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticByteFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Byte.valueOf(getByte(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ return unsafe.getByteVolatile(base, fieldOffset);
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putByteVolatile(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(b);
+ }
+ unsafe.putByteVolatile(base, fieldOffset, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticCharacterFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticCharacterFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticCharacterFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Character.valueOf(getChar(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ return unsafe.getCharVolatile(base, fieldOffset);
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Character) {
+ unsafe.putCharVolatile(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(c);
+ }
+ unsafe.putCharVolatile(base, fieldOffset, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticDoubleFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticDoubleFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticDoubleFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Double.valueOf(getDouble(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return unsafe.getDoubleVolatile(base, fieldOffset);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putDoubleVolatile(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putDoubleVolatile(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putDoubleVolatile(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putDoubleVolatile(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putDoubleVolatile(base, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putDoubleVolatile(base, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ if (value instanceof Double) {
+ unsafe.putDoubleVolatile(base, fieldOffset, ((Double) value).doubleValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(d);
+ }
+ unsafe.putDoubleVolatile(base, fieldOffset, d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2004, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import jdk.internal.misc.Unsafe;
+
+/** Base class for jdk.internal.misc.Unsafe-based FieldAccessors for final or
+ static volatile fields. */
+
+abstract class UnsafeQualifiedStaticFieldAccessorImpl
+ extends UnsafeStaticFieldAccessorImpl
+{
+ protected final boolean isReadOnly;
+
+ UnsafeQualifiedStaticFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field);
+ this.isReadOnly = isReadOnly;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticFloatFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticFloatFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticFloatFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Float.valueOf(getFloat(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return unsafe.getFloatVolatile(base, fieldOffset);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getFloat(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putFloatVolatile(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putFloatVolatile(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putFloatVolatile(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putFloatVolatile(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putFloatVolatile(base, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putFloatVolatile(base, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(f);
+ }
+ unsafe.putFloatVolatile(base, fieldOffset, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticIntegerFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticIntegerFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticIntegerFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Integer.valueOf(getInt(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return unsafe.getIntVolatile(base, fieldOffset);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putIntVolatile(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putIntVolatile(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putIntVolatile(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putIntVolatile(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(i);
+ }
+ unsafe.putIntVolatile(base, fieldOffset, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticLongFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticLongFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticLongFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Long.valueOf(getLong(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return unsafe.getLongVolatile(base, fieldOffset);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putLongVolatile(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putLongVolatile(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putLongVolatile(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putLongVolatile(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putLongVolatile(base, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(l);
+ }
+ unsafe.putLongVolatile(base, fieldOffset, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticObjectFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticObjectFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticObjectFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return unsafe.getObjectVolatile(base, fieldOffset);
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value != null) {
+ if (!field.getType().isAssignableFrom(value.getClass())) {
+ throwSetIllegalArgumentException(value);
+ }
+ }
+ unsafe.putObjectVolatile(base, fieldOffset, value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeQualifiedStaticShortFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2004, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeQualifiedStaticShortFieldAccessorImpl
+ extends UnsafeQualifiedStaticFieldAccessorImpl
+{
+ UnsafeQualifiedStaticShortFieldAccessorImpl(Field field, boolean isReadOnly) {
+ super(field, isReadOnly);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Short.valueOf(getShort(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ return unsafe.getShortVolatile(base, fieldOffset);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putShortVolatile(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putShortVolatile(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setShort(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isReadOnly) {
+ throwFinalFieldIllegalAccessException(s);
+ }
+ unsafe.putShortVolatile(base, fieldOffset, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeShortFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeShortFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ UnsafeShortFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Short.valueOf(getShort(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ ensureObj(obj);
+ return unsafe.getShort(obj, fieldOffset);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putShort(obj, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putShort(obj, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setShort(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ ensureObj(obj);
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(s);
+ }
+ unsafe.putShort(obj, fieldOffset, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticBooleanFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticBooleanFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticBooleanFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Boolean.valueOf(getBoolean(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ return unsafe.getBoolean(base, fieldOffset);
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Boolean) {
+ unsafe.putBoolean(base, fieldOffset, ((Boolean) value).booleanValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(z);
+ }
+ unsafe.putBoolean(base, fieldOffset, z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticByteFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticByteFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticByteFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Byte.valueOf(getByte(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ return unsafe.getByte(base, fieldOffset);
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getByte(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putByte(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(b);
+ }
+ unsafe.putByte(base, fieldOffset, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticCharacterFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticCharacterFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticCharacterFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Character.valueOf(getChar(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ return unsafe.getChar(base, fieldOffset);
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getChar(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Character) {
+ unsafe.putChar(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(c);
+ }
+ unsafe.putChar(base, fieldOffset, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticDoubleFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticDoubleFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticDoubleFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Double.valueOf(getDouble(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return unsafe.getDouble(base, fieldOffset);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putDouble(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putDouble(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putDouble(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putDouble(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putDouble(base, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putDouble(base, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ if (value instanceof Double) {
+ unsafe.putDouble(base, fieldOffset, ((Double) value).doubleValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setDouble(obj, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(d);
+ }
+ unsafe.putDouble(base, fieldOffset, d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2001, 2012, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import jdk.internal.misc.Unsafe;
+
+/** Base class for jdk.internal.misc.Unsafe-based FieldAccessors for static
+ fields. The observation is that there are only nine types of
+ fields from the standpoint of reflection code: the eight primitive
+ types and Object. Using class Unsafe instead of generated
+ bytecodes saves memory and loading time for the
+ dynamically-generated FieldAccessors. */
+
+abstract class UnsafeStaticFieldAccessorImpl extends UnsafeFieldAccessorImpl {
+ static {
+ Reflection.registerFieldsToFilter(UnsafeStaticFieldAccessorImpl.class,
+ new String[] { "base" });
+ }
+
+ protected final Object base; // base
+
+ UnsafeStaticFieldAccessorImpl(Field field) {
+ super(field);
+ base = unsafe.staticFieldBase(field);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticFloatFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticFloatFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticFloatFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Float.valueOf(getFloat(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return unsafe.getFloat(base, fieldOffset);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getFloat(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putFloat(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putFloat(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putFloat(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putFloat(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putFloat(base, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ if (value instanceof Float) {
+ unsafe.putFloat(base, fieldOffset, ((Float) value).floatValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setFloat(obj, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(f);
+ }
+ unsafe.putFloat(base, fieldOffset, f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticIntegerFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticIntegerFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticIntegerFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Integer.valueOf(getInt(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return unsafe.getInt(base, fieldOffset);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getInt(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putInt(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putInt(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putInt(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putInt(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setInt(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(i);
+ }
+ unsafe.putInt(base, fieldOffset, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticLongFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticLongFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticLongFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Long.valueOf(getLong(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return unsafe.getLong(base, fieldOffset);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getLong(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putLong(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putLong(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ if (value instanceof Character) {
+ unsafe.putLong(base, fieldOffset, ((Character) value).charValue());
+ return;
+ }
+ if (value instanceof Integer) {
+ unsafe.putLong(base, fieldOffset, ((Integer) value).intValue());
+ return;
+ }
+ if (value instanceof Long) {
+ unsafe.putLong(base, fieldOffset, ((Long) value).longValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setLong(obj, i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(l);
+ }
+ unsafe.putLong(base, fieldOffset, l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticObjectFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticObjectFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticObjectFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return unsafe.getObject(base, fieldOffset);
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ throw newGetShortIllegalArgumentException();
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ throw newGetIntIllegalArgumentException();
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ throw newGetLongIllegalArgumentException();
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ throw newGetFloatIllegalArgumentException();
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ throw newGetDoubleIllegalArgumentException();
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value != null) {
+ if (!field.getType().isAssignableFrom(value.getClass())) {
+ throwSetIllegalArgumentException(value);
+ }
+ }
+ unsafe.putObject(base, fieldOffset, value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/UnsafeStaticShortFieldAccessorImpl.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2001, 2005, 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.
+ */
+
+package jdk.internal.reflect;
+
+import java.lang.reflect.Field;
+
+class UnsafeStaticShortFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
+ UnsafeStaticShortFieldAccessorImpl(Field field) {
+ super(field);
+ }
+
+ public Object get(Object obj) throws IllegalArgumentException {
+ return Short.valueOf(getShort(obj));
+ }
+
+ public boolean getBoolean(Object obj) throws IllegalArgumentException {
+ throw newGetBooleanIllegalArgumentException();
+ }
+
+ public byte getByte(Object obj) throws IllegalArgumentException {
+ throw newGetByteIllegalArgumentException();
+ }
+
+ public char getChar(Object obj) throws IllegalArgumentException {
+ throw newGetCharIllegalArgumentException();
+ }
+
+ public short getShort(Object obj) throws IllegalArgumentException {
+ return unsafe.getShort(base, fieldOffset);
+ }
+
+ public int getInt(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public long getLong(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public float getFloat(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public double getDouble(Object obj) throws IllegalArgumentException {
+ return getShort(obj);
+ }
+
+ public void set(Object obj, Object value)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(value);
+ }
+ if (value == null) {
+ throwSetIllegalArgumentException(value);
+ }
+ if (value instanceof Byte) {
+ unsafe.putShort(base, fieldOffset, ((Byte) value).byteValue());
+ return;
+ }
+ if (value instanceof Short) {
+ unsafe.putShort(base, fieldOffset, ((Short) value).shortValue());
+ return;
+ }
+ throwSetIllegalArgumentException(value);
+ }
+
+ public void setBoolean(Object obj, boolean z)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(z);
+ }
+
+ public void setByte(Object obj, byte b)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ setShort(obj, b);
+ }
+
+ public void setChar(Object obj, char c)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(c);
+ }
+
+ public void setShort(Object obj, short s)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ if (isFinal) {
+ throwFinalFieldIllegalAccessException(s);
+ }
+ unsafe.putShort(base, fieldOffset, s);
+ }
+
+ public void setInt(Object obj, int i)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(i);
+ }
+
+ public void setLong(Object obj, long l)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(l);
+ }
+
+ public void setFloat(Object obj, float f)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(f);
+ }
+
+ public void setDouble(Object obj, double d)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ throwSetIllegalArgumentException(d);
+ }
+}
--- a/jdk/src/java.base/share/classes/module-info.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/module-info.java Fri Apr 15 16:19:15 2016 +0100
@@ -86,9 +86,6 @@
// see JDK-8044773
exports jdk.net;
- // This will move to a jdk.internal module via JEP-260
- exports sun.reflect;
-
// the service types defined by the APIs in this module
@@ -180,6 +177,14 @@
jdk.jvmstat;
exports jdk.internal.ref to
java.desktop;
+ exports jdk.internal.reflect to
+ java.corba,
+ java.logging,
+ java.sql,
+ java.sql.rowset,
+ jdk.dynalink,
+ jdk.scripting.nashorn,
+ jdk.unsupported;
exports jdk.internal.vm.annotation to
jdk.unsupported;
exports jdk.internal.util.jar to
--- a/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java Fri Apr 15 16:19:15 2016 +0100
@@ -28,7 +28,7 @@
import java.lang.reflect.Modifier;
import static java.lang.reflect.Modifier.*;
import java.lang.reflect.Module;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.Reflection;
/**
* This class centralizes information about the JVM's linkage access control.
--- a/jdk/src/java.base/share/classes/sun/reflect/AccessorGenerator.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,723 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.*;
-import jdk.internal.misc.Unsafe;
-
-/** Shared functionality for all accessor generators */
-
-class AccessorGenerator implements ClassFileConstants {
- static final Unsafe unsafe = Unsafe.getUnsafe();
-
- // Constants because there's no way to say "short integer constant",
- // i.e., "1S"
- protected static final short S0 = (short) 0;
- protected static final short S1 = (short) 1;
- protected static final short S2 = (short) 2;
- protected static final short S3 = (short) 3;
- protected static final short S4 = (short) 4;
- protected static final short S5 = (short) 5;
- protected static final short S6 = (short) 6;
-
- // Instance variables for shared functionality between
- // FieldAccessorGenerator and MethodAccessorGenerator
- protected ClassFileAssembler asm;
- protected int modifiers;
- protected short thisClass;
- protected short superClass;
- protected short targetClass;
- // Common constant pool entries to FieldAccessor and MethodAccessor
- protected short throwableClass;
- protected short classCastClass;
- protected short nullPointerClass;
- protected short illegalArgumentClass;
- protected short invocationTargetClass;
- protected short initIdx;
- protected short initNameAndTypeIdx;
- protected short initStringNameAndTypeIdx;
- protected short nullPointerCtorIdx;
- protected short illegalArgumentCtorIdx;
- protected short illegalArgumentStringCtorIdx;
- protected short invocationTargetCtorIdx;
- protected short superCtorIdx;
- protected short objectClass;
- protected short toStringIdx;
- protected short codeIdx;
- protected short exceptionsIdx;
- // Boxing
- protected short valueOfIdx;
- protected short booleanIdx;
- protected short booleanBoxIdx;
- protected short booleanUnboxIdx;
- protected short byteIdx;
- protected short byteBoxIdx;
- protected short byteUnboxIdx;
- protected short characterIdx;
- protected short characterBoxIdx;
- protected short characterUnboxIdx;
- protected short doubleIdx;
- protected short doubleBoxIdx;
- protected short doubleUnboxIdx;
- protected short floatIdx;
- protected short floatBoxIdx;
- protected short floatUnboxIdx;
- protected short integerIdx;
- protected short integerBoxIdx;
- protected short integerUnboxIdx;
- protected short longIdx;
- protected short longBoxIdx;
- protected short longUnboxIdx;
- protected short shortIdx;
- protected short shortBoxIdx;
- protected short shortUnboxIdx;
-
- protected final short NUM_COMMON_CPOOL_ENTRIES = (short) 30;
- protected final short NUM_BOXING_CPOOL_ENTRIES = (short) 73;
-
- // Requires that superClass has been set up
- protected void emitCommonConstantPoolEntries() {
- // + [UTF-8] "java/lang/Throwable"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/ClassCastException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/NullPointerException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/IllegalArgumentException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/InvocationTargetException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "<init>"
- // + [UTF-8] "()V"
- // + [CONSTANT_NameAndType_info] for above
- // + [CONSTANT_Methodref_info] for NullPointerException's constructor
- // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor
- // + [UTF-8] "(Ljava/lang/String;)V"
- // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/String;)V"
- // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor taking a String
- // + [UTF-8] "(Ljava/lang/Throwable;)V"
- // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/Throwable;)V"
- // + [CONSTANT_Methodref_info] for InvocationTargetException's constructor
- // + [CONSTANT_Methodref_info] for "super()"
- // + [UTF-8] "java/lang/Object"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "toString"
- // + [UTF-8] "()Ljava/lang/String;"
- // + [CONSTANT_NameAndType_info] for "toString()Ljava/lang/String;"
- // + [CONSTANT_Methodref_info] for Object's toString method
- // + [UTF-8] "Code"
- // + [UTF-8] "Exceptions"
- asm.emitConstantPoolUTF8("java/lang/Throwable");
- asm.emitConstantPoolClass(asm.cpi());
- throwableClass = asm.cpi();
- asm.emitConstantPoolUTF8("java/lang/ClassCastException");
- asm.emitConstantPoolClass(asm.cpi());
- classCastClass = asm.cpi();
- asm.emitConstantPoolUTF8("java/lang/NullPointerException");
- asm.emitConstantPoolClass(asm.cpi());
- nullPointerClass = asm.cpi();
- asm.emitConstantPoolUTF8("java/lang/IllegalArgumentException");
- asm.emitConstantPoolClass(asm.cpi());
- illegalArgumentClass = asm.cpi();
- asm.emitConstantPoolUTF8("java/lang/reflect/InvocationTargetException");
- asm.emitConstantPoolClass(asm.cpi());
- invocationTargetClass = asm.cpi();
- asm.emitConstantPoolUTF8("<init>");
- initIdx = asm.cpi();
- asm.emitConstantPoolUTF8("()V");
- asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
- initNameAndTypeIdx = asm.cpi();
- asm.emitConstantPoolMethodref(nullPointerClass, initNameAndTypeIdx);
- nullPointerCtorIdx = asm.cpi();
- asm.emitConstantPoolMethodref(illegalArgumentClass, initNameAndTypeIdx);
- illegalArgumentCtorIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(Ljava/lang/String;)V");
- asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
- initStringNameAndTypeIdx = asm.cpi();
- asm.emitConstantPoolMethodref(illegalArgumentClass, initStringNameAndTypeIdx);
- illegalArgumentStringCtorIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(Ljava/lang/Throwable;)V");
- asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
- asm.emitConstantPoolMethodref(invocationTargetClass, asm.cpi());
- invocationTargetCtorIdx = asm.cpi();
- asm.emitConstantPoolMethodref(superClass, initNameAndTypeIdx);
- superCtorIdx = asm.cpi();
- asm.emitConstantPoolUTF8("java/lang/Object");
- asm.emitConstantPoolClass(asm.cpi());
- objectClass = asm.cpi();
- asm.emitConstantPoolUTF8("toString");
- asm.emitConstantPoolUTF8("()Ljava/lang/String;");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(objectClass, asm.cpi());
- toStringIdx = asm.cpi();
- asm.emitConstantPoolUTF8("Code");
- codeIdx = asm.cpi();
- asm.emitConstantPoolUTF8("Exceptions");
- exceptionsIdx = asm.cpi();
- }
-
- /** Constant pool entries required to be able to box/unbox primitive
- types. Note that we don't emit these if we don't need them. */
- protected void emitBoxingContantPoolEntries() {
- // * [UTF-8] "valueOf"
- // * [UTF-8] "java/lang/Boolean"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(Z)Ljava/lang/Boolean;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "booleanValue"
- // * [UTF-8] "()Z"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Byte"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(B)Ljava/lang/Byte;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "byteValue"
- // * [UTF-8] "()B"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Character"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(C)Ljava/lang/Character;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "charValue"
- // * [UTF-8] "()C"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Double"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(D)Ljava/lang/Double;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "doubleValue"
- // * [UTF-8] "()D"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Float"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(F)Ljava/lang/Float;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "floatValue"
- // * [UTF-8] "()F"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Integer"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(I)Ljava/lang/Integer;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "intValue"
- // * [UTF-8] "()I"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Long"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(J)Ljava/lang/Long;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "longValue"
- // * [UTF-8] "()J"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Short"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(S)Ljava/lang/Short;"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "shortValue"
- // * [UTF-8] "()S"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
-
- // valueOf-method name
- asm.emitConstantPoolUTF8("valueOf");
- valueOfIdx = asm.cpi();
-
- // Boolean
- asm.emitConstantPoolUTF8("java/lang/Boolean");
- asm.emitConstantPoolClass(asm.cpi());
- booleanIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(Z)Ljava/lang/Boolean;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- booleanBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("booleanValue");
- asm.emitConstantPoolUTF8("()Z");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- booleanUnboxIdx = asm.cpi();
-
- // Byte
- asm.emitConstantPoolUTF8("java/lang/Byte");
- asm.emitConstantPoolClass(asm.cpi());
- byteIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(B)Ljava/lang/Byte;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- byteBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("byteValue");
- asm.emitConstantPoolUTF8("()B");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- byteUnboxIdx = asm.cpi();
-
- // Character
- asm.emitConstantPoolUTF8("java/lang/Character");
- asm.emitConstantPoolClass(asm.cpi());
- characterIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(C)Ljava/lang/Character;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- characterBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("charValue");
- asm.emitConstantPoolUTF8("()C");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- characterUnboxIdx = asm.cpi();
-
- // Double
- asm.emitConstantPoolUTF8("java/lang/Double");
- asm.emitConstantPoolClass(asm.cpi());
- doubleIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(D)Ljava/lang/Double;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- doubleBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("doubleValue");
- asm.emitConstantPoolUTF8("()D");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- doubleUnboxIdx = asm.cpi();
-
- // Float
- asm.emitConstantPoolUTF8("java/lang/Float");
- asm.emitConstantPoolClass(asm.cpi());
- floatIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(F)Ljava/lang/Float;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- floatBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("floatValue");
- asm.emitConstantPoolUTF8("()F");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- floatUnboxIdx = asm.cpi();
-
- // Integer
- asm.emitConstantPoolUTF8("java/lang/Integer");
- asm.emitConstantPoolClass(asm.cpi());
- integerIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(I)Ljava/lang/Integer;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- integerBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("intValue");
- asm.emitConstantPoolUTF8("()I");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- integerUnboxIdx = asm.cpi();
-
- // Long
- asm.emitConstantPoolUTF8("java/lang/Long");
- asm.emitConstantPoolClass(asm.cpi());
- longIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(J)Ljava/lang/Long;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- longBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("longValue");
- asm.emitConstantPoolUTF8("()J");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- longUnboxIdx = asm.cpi();
-
- // Short
- asm.emitConstantPoolUTF8("java/lang/Short");
- asm.emitConstantPoolClass(asm.cpi());
- shortIdx = asm.cpi();
- asm.emitConstantPoolUTF8("(S)Ljava/lang/Short;");
- asm.emitConstantPoolNameAndType(valueOfIdx, asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
- shortBoxIdx = asm.cpi();
- asm.emitConstantPoolUTF8("shortValue");
- asm.emitConstantPoolUTF8("()S");
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
- shortUnboxIdx = asm.cpi();
- }
-
- // Necessary because of Java's annoying promotion rules
- protected static short add(short s1, short s2) {
- return (short) (s1 + s2);
- }
-
- protected static short sub(short s1, short s2) {
- return (short) (s1 - s2);
- }
-
- protected boolean isStatic() {
- return Modifier.isStatic(modifiers);
- }
-
- protected boolean isPrivate() {
- return Modifier.isPrivate(modifiers);
- }
-
- /** Returns class name in "internal" form (i.e., '/' separators
- instead of '.') */
- protected static String getClassName
- (Class<?> c, boolean addPrefixAndSuffixForNonPrimitiveTypes)
- {
- if (c.isPrimitive()) {
- if (c == Boolean.TYPE) {
- return "Z";
- } else if (c == Byte.TYPE) {
- return "B";
- } else if (c == Character.TYPE) {
- return "C";
- } else if (c == Double.TYPE) {
- return "D";
- } else if (c == Float.TYPE) {
- return "F";
- } else if (c == Integer.TYPE) {
- return "I";
- } else if (c == Long.TYPE) {
- return "J";
- } else if (c == Short.TYPE) {
- return "S";
- } else if (c == Void.TYPE) {
- return "V";
- }
- throw new InternalError("Should have found primitive type");
- } else if (c.isArray()) {
- return "[" + getClassName(c.getComponentType(), true);
- } else {
- if (addPrefixAndSuffixForNonPrimitiveTypes) {
- return internalize("L" + c.getName() + ";");
- } else {
- return internalize(c.getName());
- }
- }
- }
-
- private static String internalize(String className) {
- return className.replace('.', '/');
- }
-
- protected void emitConstructor() {
- // Generate code into fresh code buffer
- ClassFileAssembler cb = new ClassFileAssembler();
- // 0 incoming arguments
- cb.setMaxLocals(1);
- cb.opc_aload_0();
- cb.opc_invokespecial(superCtorIdx, 0, 0);
- cb.opc_return();
-
- // Emit method
- emitMethod(initIdx, cb.getMaxLocals(), cb, null, null);
- }
-
- // The descriptor's index in the constant pool must be (1 +
- // nameIdx). "numArgs" must indicate ALL arguments, including the
- // implicit "this" argument; double and long arguments each count
- // as 2 in this count. The code buffer must NOT contain the code
- // length. The exception table may be null, but if non-null must
- // NOT contain the exception table's length. The checked exception
- // indices may be null.
- protected void emitMethod(short nameIdx,
- int numArgs,
- ClassFileAssembler code,
- ClassFileAssembler exceptionTable,
- short[] checkedExceptionIndices)
- {
- int codeLen = code.getLength();
- int excLen = 0;
- if (exceptionTable != null) {
- excLen = exceptionTable.getLength();
- if ((excLen % 8) != 0) {
- throw new IllegalArgumentException("Illegal exception table");
- }
- }
- int attrLen = 12 + codeLen + excLen;
- excLen = excLen / 8; // No-op if no exception table
-
- asm.emitShort(ACC_PUBLIC);
- asm.emitShort(nameIdx);
- asm.emitShort(add(nameIdx, S1));
- if (checkedExceptionIndices == null) {
- // Code attribute only
- asm.emitShort(S1);
- } else {
- // Code and Exceptions attributes
- asm.emitShort(S2);
- }
- // Code attribute
- asm.emitShort(codeIdx);
- asm.emitInt(attrLen);
- asm.emitShort(code.getMaxStack());
- asm.emitShort((short) Math.max(numArgs, code.getMaxLocals()));
- asm.emitInt(codeLen);
- asm.append(code);
- asm.emitShort((short) excLen);
- if (exceptionTable != null) {
- asm.append(exceptionTable);
- }
- asm.emitShort(S0); // No additional attributes for Code attribute
- if (checkedExceptionIndices != null) {
- // Exceptions attribute
- asm.emitShort(exceptionsIdx);
- asm.emitInt(2 + 2 * checkedExceptionIndices.length);
- asm.emitShort((short) checkedExceptionIndices.length);
- for (int i = 0; i < checkedExceptionIndices.length; i++) {
- asm.emitShort(checkedExceptionIndices[i]);
- }
- }
- }
-
- protected short indexForPrimitiveType(Class<?> type) {
- if (type == Boolean.TYPE) {
- return booleanIdx;
- } else if (type == Byte.TYPE) {
- return byteIdx;
- } else if (type == Character.TYPE) {
- return characterIdx;
- } else if (type == Double.TYPE) {
- return doubleIdx;
- } else if (type == Float.TYPE) {
- return floatIdx;
- } else if (type == Integer.TYPE) {
- return integerIdx;
- } else if (type == Long.TYPE) {
- return longIdx;
- } else if (type == Short.TYPE) {
- return shortIdx;
- }
- throw new InternalError("Should have found primitive type");
- }
-
- protected short boxingMethodForPrimitiveType(Class<?> type) {
- if (type == Boolean.TYPE) {
- return booleanBoxIdx;
- } else if (type == Byte.TYPE) {
- return byteBoxIdx;
- } else if (type == Character.TYPE) {
- return characterBoxIdx;
- } else if (type == Double.TYPE) {
- return doubleBoxIdx;
- } else if (type == Float.TYPE) {
- return floatBoxIdx;
- } else if (type == Integer.TYPE) {
- return integerBoxIdx;
- } else if (type == Long.TYPE) {
- return longBoxIdx;
- } else if (type == Short.TYPE) {
- return shortBoxIdx;
- }
- throw new InternalError("Should have found primitive type");
- }
-
- /** Returns true for widening or identity conversions for primitive
- types only */
- protected static boolean canWidenTo(Class<?> type, Class<?> otherType) {
- if (!type.isPrimitive()) {
- return false;
- }
-
- // Widening conversions (from JVM spec):
- // byte to short, int, long, float, or double
- // short to int, long, float, or double
- // char to int, long, float, or double
- // int to long, float, or double
- // long to float or double
- // float to double
-
- if (type == Boolean.TYPE) {
- if (otherType == Boolean.TYPE) {
- return true;
- }
- } else if (type == Byte.TYPE) {
- if ( otherType == Byte.TYPE
- || otherType == Short.TYPE
- || otherType == Integer.TYPE
- || otherType == Long.TYPE
- || otherType == Float.TYPE
- || otherType == Double.TYPE) {
- return true;
- }
- } else if (type == Short.TYPE) {
- if ( otherType == Short.TYPE
- || otherType == Integer.TYPE
- || otherType == Long.TYPE
- || otherType == Float.TYPE
- || otherType == Double.TYPE) {
- return true;
- }
- } else if (type == Character.TYPE) {
- if ( otherType == Character.TYPE
- || otherType == Integer.TYPE
- || otherType == Long.TYPE
- || otherType == Float.TYPE
- || otherType == Double.TYPE) {
- return true;
- }
- } else if (type == Integer.TYPE) {
- if ( otherType == Integer.TYPE
- || otherType == Long.TYPE
- || otherType == Float.TYPE
- || otherType == Double.TYPE) {
- return true;
- }
- } else if (type == Long.TYPE) {
- if ( otherType == Long.TYPE
- || otherType == Float.TYPE
- || otherType == Double.TYPE) {
- return true;
- }
- } else if (type == Float.TYPE) {
- if ( otherType == Float.TYPE
- || otherType == Double.TYPE) {
- return true;
- }
- } else if (type == Double.TYPE) {
- if (otherType == Double.TYPE) {
- return true;
- }
- }
-
- return false;
- }
-
- /** Emits the widening bytecode for the given primitive conversion
- (or none if the identity conversion). Requires that a primitive
- conversion exists; i.e., canWidenTo must have already been
- called and returned true. */
- protected static void emitWideningBytecodeForPrimitiveConversion
- (ClassFileAssembler cb,
- Class<?> fromType,
- Class<?> toType)
- {
- // Note that widening conversions for integral types (i.e., "b2s",
- // "s2i") are no-ops since values on the Java stack are
- // sign-extended.
-
- // Widening conversions (from JVM spec):
- // byte to short, int, long, float, or double
- // short to int, long, float, or double
- // char to int, long, float, or double
- // int to long, float, or double
- // long to float or double
- // float to double
-
- if ( fromType == Byte.TYPE
- || fromType == Short.TYPE
- || fromType == Character.TYPE
- || fromType == Integer.TYPE) {
- if (toType == Long.TYPE) {
- cb.opc_i2l();
- } else if (toType == Float.TYPE) {
- cb.opc_i2f();
- } else if (toType == Double.TYPE) {
- cb.opc_i2d();
- }
- } else if (fromType == Long.TYPE) {
- if (toType == Float.TYPE) {
- cb.opc_l2f();
- } else if (toType == Double.TYPE) {
- cb.opc_l2d();
- }
- } else if (fromType == Float.TYPE) {
- if (toType == Double.TYPE) {
- cb.opc_f2d();
- }
- }
-
- // Otherwise, was identity or no-op conversion. Fall through.
- }
-
- protected short unboxingMethodForPrimitiveType(Class<?> primType) {
- if (primType == Boolean.TYPE) {
- return booleanUnboxIdx;
- } else if (primType == Byte.TYPE) {
- return byteUnboxIdx;
- } else if (primType == Character.TYPE) {
- return characterUnboxIdx;
- } else if (primType == Short.TYPE) {
- return shortUnboxIdx;
- } else if (primType == Integer.TYPE) {
- return integerUnboxIdx;
- } else if (primType == Long.TYPE) {
- return longUnboxIdx;
- } else if (primType == Float.TYPE) {
- return floatUnboxIdx;
- } else if (primType == Double.TYPE) {
- return doubleUnboxIdx;
- }
- throw new InternalError("Illegal primitive type " + primType.getName());
- }
-
- protected static final Class<?>[] primitiveTypes = new Class<?>[] {
- Boolean.TYPE,
- Byte.TYPE,
- Character.TYPE,
- Short.TYPE,
- Integer.TYPE,
- Long.TYPE,
- Float.TYPE,
- Double.TYPE
- };
-
- /** We don't consider "Void" to be a primitive type */
- protected static boolean isPrimitive(Class<?> c) {
- return (c.isPrimitive() && c != Void.TYPE);
- }
-
- protected int typeSizeInStackSlots(Class<?> c) {
- if (c == Void.TYPE) {
- return 0;
- }
- if (c == Long.TYPE || c == Double.TYPE) {
- return 2;
- }
- return 1;
- }
-
- private ClassFileAssembler illegalArgumentCodeBuffer;
- protected ClassFileAssembler illegalArgumentCodeBuffer() {
- if (illegalArgumentCodeBuffer == null) {
- illegalArgumentCodeBuffer = new ClassFileAssembler();
- illegalArgumentCodeBuffer.opc_new(illegalArgumentClass);
- illegalArgumentCodeBuffer.opc_dup();
- illegalArgumentCodeBuffer.opc_invokespecial(illegalArgumentCtorIdx, 0, 0);
- illegalArgumentCodeBuffer.opc_athrow();
- }
-
- return illegalArgumentCodeBuffer;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/BootstrapConstructorAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2001, 2011, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Constructor;
-
-/** Uses Unsafe.allocateObject() to instantiate classes; only used for
- bootstrapping. */
-
-class BootstrapConstructorAccessorImpl extends ConstructorAccessorImpl {
- private final Constructor<?> constructor;
-
- BootstrapConstructorAccessorImpl(Constructor<?> c) {
- this.constructor = c;
- }
-
- public Object newInstance(Object[] args)
- throws IllegalArgumentException, InvocationTargetException
- {
- try {
- return UnsafeFieldAccessorImpl.unsafe.
- allocateInstance(constructor.getDeclaringClass());
- } catch (InstantiationException e) {
- throw new InvocationTargetException(e);
- }
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ByteVector.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-/** A growable array of bytes. */
-
-interface ByteVector {
- public int getLength();
- public byte get(int index);
- public void put(int index, byte value);
- public void add(byte value);
- public void trim();
- public byte[] getData();
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ByteVectorFactory.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-class ByteVectorFactory {
- static ByteVector create() {
- return new ByteVectorImpl();
- }
-
- static ByteVector create(int sz) {
- return new ByteVectorImpl(sz);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ByteVectorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-class ByteVectorImpl implements ByteVector {
- private byte[] data;
- private int pos;
-
- public ByteVectorImpl() {
- this(100);
- }
-
- public ByteVectorImpl(int sz) {
- data = new byte[sz];
- pos = -1;
- }
-
- public int getLength() {
- return pos + 1;
- }
-
- public byte get(int index) {
- if (index >= data.length) {
- resize(index);
- pos = index;
- }
- return data[index];
- }
-
- public void put(int index, byte value) {
- if (index >= data.length) {
- resize(index);
- pos = index;
- }
- data[index] = value;
- }
-
- public void add(byte value) {
- if (++pos >= data.length) {
- resize(pos);
- }
- data[pos] = value;
- }
-
- public void trim() {
- if (pos != data.length - 1) {
- byte[] newData = new byte[pos + 1];
- System.arraycopy(data, 0, newData, 0, pos + 1);
- data = newData;
- }
- }
-
- public byte[] getData() {
- return data;
- }
-
- private void resize(int minSize) {
- if (minSize <= 2 * data.length) {
- minSize = 2 * data.length;
- }
- byte[] newData = new byte[minSize];
- System.arraycopy(data, 0, newData, 0, data.length);
- data = newData;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/CallerSensitive.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * 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.
- */
-
-package sun.reflect;
-
-import java.lang.annotation.*;
-import static java.lang.annotation.ElementType.*;
-
-/**
- * A method annotated @CallerSensitive is sensitive to its calling class,
- * via {@link sun.reflect.Reflection#getCallerClass Reflection.getCallerClass},
- * or via some equivalent.
- *
- * @author John R. Rose
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({METHOD})
-public @interface CallerSensitive {
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ClassDefiner.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2001, 2011, 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.
- */
-
-package sun.reflect;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import jdk.internal.misc.Unsafe;
-
-/** Utility class which assists in calling Unsafe.defineClass() by
- creating a new class loader which delegates to the one needed in
- order for proper resolution of the given bytecodes to occur. */
-
-class ClassDefiner {
- static final Unsafe unsafe = Unsafe.getUnsafe();
-
- /** <P> We define generated code into a new class loader which
- delegates to the defining loader of the target class. It is
- necessary for the VM to be able to resolve references to the
- target class from the generated bytecodes, which could not occur
- if the generated code was loaded into the bootstrap class
- loader. </P>
-
- <P> There are two primary reasons for creating a new loader
- instead of defining these bytecodes directly into the defining
- loader of the target class: first, it avoids any possible
- security risk of having these bytecodes in the same loader.
- Second, it allows the generated bytecodes to be unloaded earlier
- than would otherwise be possible, decreasing run-time
- footprint. </P>
- */
- static Class<?> defineClass(String name, byte[] bytes, int off, int len,
- final ClassLoader parentClassLoader)
- {
- ClassLoader newLoader = AccessController.doPrivileged(
- new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return new DelegatingClassLoader(parentClassLoader);
- }
- });
- return unsafe.defineClass(name, bytes, off, len, newLoader, null);
- }
-}
-
-
-// NOTE: this class's name and presence are known to the virtual
-// machine as of the fix for 4474172.
-class DelegatingClassLoader extends ClassLoader {
- DelegatingClassLoader(ClassLoader parent) {
- super(parent);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ClassFileAssembler.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,671 +0,0 @@
-/*
- * Copyright (c) 2001, 2004, 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.
- */
-
-package sun.reflect;
-
-class ClassFileAssembler implements ClassFileConstants {
- private ByteVector vec;
- private short cpIdx = 0;
-
- public ClassFileAssembler() {
- this(ByteVectorFactory.create());
- }
-
- public ClassFileAssembler(ByteVector vec) {
- this.vec = vec;
- }
-
- public ByteVector getData() {
- return vec;
- }
-
- /** Length in bytes */
- public short getLength() {
- return (short) vec.getLength();
- }
-
- public void emitMagicAndVersion() {
- emitInt(0xCAFEBABE);
- emitShort((short) 0);
- emitShort((short) 49);
- }
-
- public void emitInt(int val) {
- emitByte((byte) (val >> 24));
- emitByte((byte) ((val >> 16) & 0xFF));
- emitByte((byte) ((val >> 8) & 0xFF));
- emitByte((byte) (val & 0xFF));
- }
-
- public void emitShort(short val) {
- emitByte((byte) ((val >> 8) & 0xFF));
- emitByte((byte) (val & 0xFF));
- }
-
- // Support for labels; package-private
- void emitShort(short bci, short val) {
- vec.put(bci, (byte) ((val >> 8) & 0xFF));
- vec.put(bci + 1, (byte) (val & 0xFF));
- }
-
- public void emitByte(byte val) {
- vec.add(val);
- }
-
- public void append(ClassFileAssembler asm) {
- append(asm.vec);
- }
-
- public void append(ByteVector vec) {
- for (int i = 0; i < vec.getLength(); i++) {
- emitByte(vec.get(i));
- }
- }
-
- /** Keeps track of the current (one-based) constant pool index;
- incremented after emitting one of the following constant pool
- entries. Can fetch the current constant pool index for use in
- later entries. Index points at the last valid constant pool
- entry; initially invalid. It is illegal to fetch the constant
- pool index before emitting at least one constant pool entry. */
- public short cpi() {
- if (cpIdx == 0) {
- throw new RuntimeException("Illegal use of ClassFileAssembler");
- }
- return cpIdx;
- }
-
- public void emitConstantPoolUTF8(String str) {
- // NOTE: can not use str.getBytes("UTF-8") here because of
- // bootstrapping issues with the character set converters.
- byte[] bytes = UTF8.encode(str);
- emitByte(CONSTANT_Utf8);
- emitShort((short) bytes.length);
- for (int i = 0; i < bytes.length; i++) {
- emitByte(bytes[i]);
- }
- cpIdx++;
- }
-
- public void emitConstantPoolClass(short index) {
- emitByte(CONSTANT_Class);
- emitShort(index);
- cpIdx++;
- }
-
- public void emitConstantPoolNameAndType(short nameIndex, short typeIndex) {
- emitByte(CONSTANT_NameAndType);
- emitShort(nameIndex);
- emitShort(typeIndex);
- cpIdx++;
- }
-
- public void emitConstantPoolFieldref
- (short classIndex, short nameAndTypeIndex)
- {
- emitByte(CONSTANT_Fieldref);
- emitShort(classIndex);
- emitShort(nameAndTypeIndex);
- cpIdx++;
- }
-
- public void emitConstantPoolMethodref
- (short classIndex, short nameAndTypeIndex)
- {
- emitByte(CONSTANT_Methodref);
- emitShort(classIndex);
- emitShort(nameAndTypeIndex);
- cpIdx++;
- }
-
- public void emitConstantPoolInterfaceMethodref
- (short classIndex, short nameAndTypeIndex)
- {
- emitByte(CONSTANT_InterfaceMethodref);
- emitShort(classIndex);
- emitShort(nameAndTypeIndex);
- cpIdx++;
- }
-
- public void emitConstantPoolString(short utf8Index) {
- emitByte(CONSTANT_String);
- emitShort(utf8Index);
- cpIdx++;
- }
-
- //----------------------------------------------------------------------
- // Opcodes. Keeps track of maximum stack and locals. Make a new
- // assembler for each piece of assembled code, then append the
- // result to the previous assembler's class file.
- //
-
- private int stack = 0;
- private int maxStack = 0;
- private int maxLocals = 0;
-
- private void incStack() {
- setStack(stack + 1);
- }
-
- private void decStack() {
- --stack;
- }
-
- public short getMaxStack() {
- return (short) maxStack;
- }
-
- public short getMaxLocals() {
- return (short) maxLocals;
- }
-
- /** It's necessary to be able to specify the number of arguments at
- the beginning of the method (which translates to the initial
- value of max locals) */
- public void setMaxLocals(int maxLocals) {
- this.maxLocals = maxLocals;
- }
-
- /** Needed to do flow control. Returns current stack depth. */
- public int getStack() {
- return stack;
- }
-
- /** Needed to do flow control. */
- public void setStack(int value) {
- stack = value;
- if (stack > maxStack) {
- maxStack = stack;
- }
- }
-
- ///////////////
- // Constants //
- ///////////////
-
- public void opc_aconst_null() {
- emitByte(opc_aconst_null);
- incStack();
- }
-
- public void opc_sipush(short constant) {
- emitByte(opc_sipush);
- emitShort(constant);
- incStack();
- }
-
- public void opc_ldc(byte cpIdx) {
- emitByte(opc_ldc);
- emitByte(cpIdx);
- incStack();
- }
-
- /////////////////////////////////////
- // Local variable loads and stores //
- /////////////////////////////////////
-
- public void opc_iload_0() {
- emitByte(opc_iload_0);
- if (maxLocals < 1) maxLocals = 1;
- incStack();
- }
-
- public void opc_iload_1() {
- emitByte(opc_iload_1);
- if (maxLocals < 2) maxLocals = 2;
- incStack();
- }
-
- public void opc_iload_2() {
- emitByte(opc_iload_2);
- if (maxLocals < 3) maxLocals = 3;
- incStack();
- }
-
- public void opc_iload_3() {
- emitByte(opc_iload_3);
- if (maxLocals < 4) maxLocals = 4;
- incStack();
- }
-
- public void opc_lload_0() {
- emitByte(opc_lload_0);
- if (maxLocals < 2) maxLocals = 2;
- incStack();
- incStack();
- }
-
- public void opc_lload_1() {
- emitByte(opc_lload_1);
- if (maxLocals < 3) maxLocals = 3;
- incStack();
- incStack();
- }
-
- public void opc_lload_2() {
- emitByte(opc_lload_2);
- if (maxLocals < 4) maxLocals = 4;
- incStack();
- incStack();
- }
-
- public void opc_lload_3() {
- emitByte(opc_lload_3);
- if (maxLocals < 5) maxLocals = 5;
- incStack();
- incStack();
- }
-
- public void opc_fload_0() {
- emitByte(opc_fload_0);
- if (maxLocals < 1) maxLocals = 1;
- incStack();
- }
-
- public void opc_fload_1() {
- emitByte(opc_fload_1);
- if (maxLocals < 2) maxLocals = 2;
- incStack();
- }
-
- public void opc_fload_2() {
- emitByte(opc_fload_2);
- if (maxLocals < 3) maxLocals = 3;
- incStack();
- }
-
- public void opc_fload_3() {
- emitByte(opc_fload_3);
- if (maxLocals < 4) maxLocals = 4;
- incStack();
- }
-
- public void opc_dload_0() {
- emitByte(opc_dload_0);
- if (maxLocals < 2) maxLocals = 2;
- incStack();
- incStack();
- }
-
- public void opc_dload_1() {
- emitByte(opc_dload_1);
- if (maxLocals < 3) maxLocals = 3;
- incStack();
- incStack();
- }
-
- public void opc_dload_2() {
- emitByte(opc_dload_2);
- if (maxLocals < 4) maxLocals = 4;
- incStack();
- incStack();
- }
-
- public void opc_dload_3() {
- emitByte(opc_dload_3);
- if (maxLocals < 5) maxLocals = 5;
- incStack();
- incStack();
- }
-
- public void opc_aload_0() {
- emitByte(opc_aload_0);
- if (maxLocals < 1) maxLocals = 1;
- incStack();
- }
-
- public void opc_aload_1() {
- emitByte(opc_aload_1);
- if (maxLocals < 2) maxLocals = 2;
- incStack();
- }
-
- public void opc_aload_2() {
- emitByte(opc_aload_2);
- if (maxLocals < 3) maxLocals = 3;
- incStack();
- }
-
- public void opc_aload_3() {
- emitByte(opc_aload_3);
- if (maxLocals < 4) maxLocals = 4;
- incStack();
- }
-
- public void opc_aaload() {
- emitByte(opc_aaload);
- decStack();
- }
-
- public void opc_astore_0() {
- emitByte(opc_astore_0);
- if (maxLocals < 1) maxLocals = 1;
- decStack();
- }
-
- public void opc_astore_1() {
- emitByte(opc_astore_1);
- if (maxLocals < 2) maxLocals = 2;
- decStack();
- }
-
- public void opc_astore_2() {
- emitByte(opc_astore_2);
- if (maxLocals < 3) maxLocals = 3;
- decStack();
- }
-
- public void opc_astore_3() {
- emitByte(opc_astore_3);
- if (maxLocals < 4) maxLocals = 4;
- decStack();
- }
-
- ////////////////////////
- // Stack manipulation //
- ////////////////////////
-
- public void opc_pop() {
- emitByte(opc_pop);
- decStack();
- }
-
- public void opc_dup() {
- emitByte(opc_dup);
- incStack();
- }
-
- public void opc_dup_x1() {
- emitByte(opc_dup_x1);
- incStack();
- }
-
- public void opc_swap() {
- emitByte(opc_swap);
- }
-
- ///////////////////////////////
- // Widening conversions only //
- ///////////////////////////////
-
- public void opc_i2l() {
- emitByte(opc_i2l);
- }
-
- public void opc_i2f() {
- emitByte(opc_i2f);
- }
-
- public void opc_i2d() {
- emitByte(opc_i2d);
- }
-
- public void opc_l2f() {
- emitByte(opc_l2f);
- }
-
- public void opc_l2d() {
- emitByte(opc_l2d);
- }
-
- public void opc_f2d() {
- emitByte(opc_f2d);
- }
-
- //////////////////
- // Control flow //
- //////////////////
-
- public void opc_ifeq(short bciOffset) {
- emitByte(opc_ifeq);
- emitShort(bciOffset);
- decStack();
- }
-
- /** Control flow with forward-reference BCI. Stack assumes
- straight-through control flow. */
- public void opc_ifeq(Label l) {
- short instrBCI = getLength();
- emitByte(opc_ifeq);
- l.add(this, instrBCI, getLength(), getStack() - 1);
- emitShort((short) -1); // Must be patched later
- }
-
- public void opc_if_icmpeq(short bciOffset) {
- emitByte(opc_if_icmpeq);
- emitShort(bciOffset);
- setStack(getStack() - 2);
- }
-
- /** Control flow with forward-reference BCI. Stack assumes straight
- control flow. */
- public void opc_if_icmpeq(Label l) {
- short instrBCI = getLength();
- emitByte(opc_if_icmpeq);
- l.add(this, instrBCI, getLength(), getStack() - 2);
- emitShort((short) -1); // Must be patched later
- }
-
- public void opc_goto(short bciOffset) {
- emitByte(opc_goto);
- emitShort(bciOffset);
- }
-
- /** Control flow with forward-reference BCI. Stack assumes straight
- control flow. */
- public void opc_goto(Label l) {
- short instrBCI = getLength();
- emitByte(opc_goto);
- l.add(this, instrBCI, getLength(), getStack());
- emitShort((short) -1); // Must be patched later
- }
-
- public void opc_ifnull(short bciOffset) {
- emitByte(opc_ifnull);
- emitShort(bciOffset);
- decStack();
- }
-
- /** Control flow with forward-reference BCI. Stack assumes straight
- control flow. */
- public void opc_ifnull(Label l) {
- short instrBCI = getLength();
- emitByte(opc_ifnull);
- l.add(this, instrBCI, getLength(), getStack() - 1);
- emitShort((short) -1); // Must be patched later
- decStack();
- }
-
- public void opc_ifnonnull(short bciOffset) {
- emitByte(opc_ifnonnull);
- emitShort(bciOffset);
- decStack();
- }
-
- /** Control flow with forward-reference BCI. Stack assumes straight
- control flow. */
- public void opc_ifnonnull(Label l) {
- short instrBCI = getLength();
- emitByte(opc_ifnonnull);
- l.add(this, instrBCI, getLength(), getStack() - 1);
- emitShort((short) -1); // Must be patched later
- decStack();
- }
-
- /////////////////////////
- // Return instructions //
- /////////////////////////
-
- public void opc_ireturn() {
- emitByte(opc_ireturn);
- setStack(0);
- }
-
- public void opc_lreturn() {
- emitByte(opc_lreturn);
- setStack(0);
- }
-
- public void opc_freturn() {
- emitByte(opc_freturn);
- setStack(0);
- }
-
- public void opc_dreturn() {
- emitByte(opc_dreturn);
- setStack(0);
- }
-
- public void opc_areturn() {
- emitByte(opc_areturn);
- setStack(0);
- }
-
- public void opc_return() {
- emitByte(opc_return);
- setStack(0);
- }
-
- //////////////////////
- // Field operations //
- //////////////////////
-
- public void opc_getstatic(short fieldIndex, int fieldSizeInStackSlots) {
- emitByte(opc_getstatic);
- emitShort(fieldIndex);
- setStack(getStack() + fieldSizeInStackSlots);
- }
-
- public void opc_putstatic(short fieldIndex, int fieldSizeInStackSlots) {
- emitByte(opc_putstatic);
- emitShort(fieldIndex);
- setStack(getStack() - fieldSizeInStackSlots);
- }
-
- public void opc_getfield(short fieldIndex, int fieldSizeInStackSlots) {
- emitByte(opc_getfield);
- emitShort(fieldIndex);
- setStack(getStack() + fieldSizeInStackSlots - 1);
- }
-
- public void opc_putfield(short fieldIndex, int fieldSizeInStackSlots) {
- emitByte(opc_putfield);
- emitShort(fieldIndex);
- setStack(getStack() - fieldSizeInStackSlots - 1);
- }
-
- ////////////////////////
- // Method invocations //
- ////////////////////////
-
- /** Long and double arguments and return types count as 2 arguments;
- other values count as 1. */
- public void opc_invokevirtual(short methodIndex,
- int numArgs,
- int numReturnValues)
- {
- emitByte(opc_invokevirtual);
- emitShort(methodIndex);
- setStack(getStack() - numArgs - 1 + numReturnValues);
- }
-
- /** Long and double arguments and return types count as 2 arguments;
- other values count as 1. */
- public void opc_invokespecial(short methodIndex,
- int numArgs,
- int numReturnValues)
- {
- emitByte(opc_invokespecial);
- emitShort(methodIndex);
- setStack(getStack() - numArgs - 1 + numReturnValues);
- }
-
- /** Long and double arguments and return types count as 2 arguments;
- other values count as 1. */
- public void opc_invokestatic(short methodIndex,
- int numArgs,
- int numReturnValues)
- {
- emitByte(opc_invokestatic);
- emitShort(methodIndex);
- setStack(getStack() - numArgs + numReturnValues);
- }
-
- /** Long and double arguments and return types count as 2 arguments;
- other values count as 1. */
- public void opc_invokeinterface(short methodIndex,
- int numArgs,
- byte count,
- int numReturnValues)
- {
- emitByte(opc_invokeinterface);
- emitShort(methodIndex);
- emitByte(count);
- emitByte((byte) 0);
- setStack(getStack() - numArgs - 1 + numReturnValues);
- }
-
- //////////////////
- // Array length //
- //////////////////
-
- public void opc_arraylength() {
- emitByte(opc_arraylength);
- }
-
- /////////
- // New //
- /////////
-
- public void opc_new(short classIndex) {
- emitByte(opc_new);
- emitShort(classIndex);
- incStack();
- }
-
- ////////////
- // Athrow //
- ////////////
-
- public void opc_athrow() {
- emitByte(opc_athrow);
- setStack(1);
- }
-
- //////////////////////////////
- // Checkcast and instanceof //
- //////////////////////////////
-
- /** Assumes the checkcast succeeds */
- public void opc_checkcast(short classIndex) {
- emitByte(opc_checkcast);
- emitShort(classIndex);
- }
-
- public void opc_instanceof(short classIndex) {
- emitByte(opc_instanceof);
- emitShort(classIndex);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ClassFileConstants.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-/** Minimal set of class file constants for assembly of field and
- method accessors. */
-
-interface ClassFileConstants {
- // Constants
- public static final byte opc_aconst_null = (byte) 0x1;
- public static final byte opc_sipush = (byte) 0x11;
- public static final byte opc_ldc = (byte) 0x12;
-
- // Local variable loads and stores
- public static final byte opc_iload_0 = (byte) 0x1a;
- public static final byte opc_iload_1 = (byte) 0x1b;
- public static final byte opc_iload_2 = (byte) 0x1c;
- public static final byte opc_iload_3 = (byte) 0x1d;
- public static final byte opc_lload_0 = (byte) 0x1e;
- public static final byte opc_lload_1 = (byte) 0x1f;
- public static final byte opc_lload_2 = (byte) 0x20;
- public static final byte opc_lload_3 = (byte) 0x21;
- public static final byte opc_fload_0 = (byte) 0x22;
- public static final byte opc_fload_1 = (byte) 0x23;
- public static final byte opc_fload_2 = (byte) 0x24;
- public static final byte opc_fload_3 = (byte) 0x25;
- public static final byte opc_dload_0 = (byte) 0x26;
- public static final byte opc_dload_1 = (byte) 0x27;
- public static final byte opc_dload_2 = (byte) 0x28;
- public static final byte opc_dload_3 = (byte) 0x29;
- public static final byte opc_aload_0 = (byte) 0x2a;
- public static final byte opc_aload_1 = (byte) 0x2b;
- public static final byte opc_aload_2 = (byte) 0x2c;
- public static final byte opc_aload_3 = (byte) 0x2d;
- public static final byte opc_aaload = (byte) 0x32;
- public static final byte opc_astore_0 = (byte) 0x4b;
- public static final byte opc_astore_1 = (byte) 0x4c;
- public static final byte opc_astore_2 = (byte) 0x4d;
- public static final byte opc_astore_3 = (byte) 0x4e;
-
- // Stack manipulation
- public static final byte opc_pop = (byte) 0x57;
- public static final byte opc_dup = (byte) 0x59;
- public static final byte opc_dup_x1 = (byte) 0x5a;
- public static final byte opc_swap = (byte) 0x5f;
-
- // Conversions
- public static final byte opc_i2l = (byte) 0x85;
- public static final byte opc_i2f = (byte) 0x86;
- public static final byte opc_i2d = (byte) 0x87;
- public static final byte opc_l2i = (byte) 0x88;
- public static final byte opc_l2f = (byte) 0x89;
- public static final byte opc_l2d = (byte) 0x8a;
- public static final byte opc_f2i = (byte) 0x8b;
- public static final byte opc_f2l = (byte) 0x8c;
- public static final byte opc_f2d = (byte) 0x8d;
- public static final byte opc_d2i = (byte) 0x8e;
- public static final byte opc_d2l = (byte) 0x8f;
- public static final byte opc_d2f = (byte) 0x90;
- public static final byte opc_i2b = (byte) 0x91;
- public static final byte opc_i2c = (byte) 0x92;
- public static final byte opc_i2s = (byte) 0x93;
-
- // Control flow
- public static final byte opc_ifeq = (byte) 0x99;
- public static final byte opc_if_icmpeq = (byte) 0x9f;
- public static final byte opc_goto = (byte) 0xa7;
-
- // Return instructions
- public static final byte opc_ireturn = (byte) 0xac;
- public static final byte opc_lreturn = (byte) 0xad;
- public static final byte opc_freturn = (byte) 0xae;
- public static final byte opc_dreturn = (byte) 0xaf;
- public static final byte opc_areturn = (byte) 0xb0;
- public static final byte opc_return = (byte) 0xb1;
-
- // Field operations
- public static final byte opc_getstatic = (byte) 0xb2;
- public static final byte opc_putstatic = (byte) 0xb3;
- public static final byte opc_getfield = (byte) 0xb4;
- public static final byte opc_putfield = (byte) 0xb5;
-
- // Method invocations
- public static final byte opc_invokevirtual = (byte) 0xb6;
- public static final byte opc_invokespecial = (byte) 0xb7;
- public static final byte opc_invokestatic = (byte) 0xb8;
- public static final byte opc_invokeinterface = (byte) 0xb9;
-
- // Array length
- public static final byte opc_arraylength = (byte) 0xbe;
-
- // New
- public static final byte opc_new = (byte) 0xbb;
-
- // Athrow
- public static final byte opc_athrow = (byte) 0xbf;
-
- // Checkcast and instanceof
- public static final byte opc_checkcast = (byte) 0xc0;
- public static final byte opc_instanceof = (byte) 0xc1;
-
- // Ifnull and ifnonnull
- public static final byte opc_ifnull = (byte) 0xc6;
- public static final byte opc_ifnonnull = (byte) 0xc7;
-
- // Constant pool tags
- public static final byte CONSTANT_Class = (byte) 7;
- public static final byte CONSTANT_Fieldref = (byte) 9;
- public static final byte CONSTANT_Methodref = (byte) 10;
- public static final byte CONSTANT_InterfaceMethodref = (byte) 11;
- public static final byte CONSTANT_NameAndType = (byte) 12;
- public static final byte CONSTANT_String = (byte) 8;
- public static final byte CONSTANT_Utf8 = (byte) 1;
-
- // Access flags
- public static final short ACC_PUBLIC = (short) 0x0001;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ConstantPool.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/*
- * Copyright (c) 2003, 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
- * 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.*;
-
-/** Provides reflective access to the constant pools of classes.
- Currently this is needed to provide reflective access to annotations
- but may be used by other internal subsystems in the future. */
-
-public class ConstantPool {
- // Number of entries in this constant pool (= maximum valid constant pool index)
- public int getSize() { return getSize0 (constantPoolOop); }
- public Class<?> getClassAt (int index) { return getClassAt0 (constantPoolOop, index); }
- public Class<?> getClassAtIfLoaded (int index) { return getClassAtIfLoaded0 (constantPoolOop, index); }
- // Returns a class reference index for a method or a field.
- public int getClassRefIndexAt(int index) {
- return getClassRefIndexAt0(constantPoolOop, index);
- }
- // Returns either a Method or Constructor.
- // Static initializers are returned as Method objects.
- public Member getMethodAt (int index) { return getMethodAt0 (constantPoolOop, index); }
- public Member getMethodAtIfLoaded(int index) { return getMethodAtIfLoaded0(constantPoolOop, index); }
- public Field getFieldAt (int index) { return getFieldAt0 (constantPoolOop, index); }
- public Field getFieldAtIfLoaded (int index) { return getFieldAtIfLoaded0 (constantPoolOop, index); }
- // Fetches the class name, member (field, method or interface
- // method) name, and type descriptor as an array of three Strings
- public String[] getMemberRefInfoAt (int index) { return getMemberRefInfoAt0 (constantPoolOop, index); }
- // Returns a name and type reference index for a method, a field or an invokedynamic.
- public int getNameAndTypeRefIndexAt(int index) {
- return getNameAndTypeRefIndexAt0(constantPoolOop, index);
- }
- // Fetches the name and type from name_and_type index as an array of two Strings
- public String[] getNameAndTypeRefInfoAt(int index) {
- return getNameAndTypeRefInfoAt0(constantPoolOop, index);
- }
- public int getIntAt (int index) { return getIntAt0 (constantPoolOop, index); }
- public long getLongAt (int index) { return getLongAt0 (constantPoolOop, index); }
- public float getFloatAt (int index) { return getFloatAt0 (constantPoolOop, index); }
- public double getDoubleAt (int index) { return getDoubleAt0 (constantPoolOop, index); }
- public String getStringAt (int index) { return getStringAt0 (constantPoolOop, index); }
- public String getUTF8At (int index) { return getUTF8At0 (constantPoolOop, index); }
- public Tag getTagAt(int index) {
- return Tag.valueOf(getTagAt0(constantPoolOop, index));
- }
-
- public static enum Tag {
- UTF8(1),
- INTEGER(3),
- FLOAT(4),
- LONG(5),
- DOUBLE(6),
- CLASS(7),
- STRING(8),
- FIELDREF(9),
- METHODREF(10),
- INTERFACEMETHODREF(11),
- NAMEANDTYPE(12),
- METHODHANDLE(15),
- METHODTYPE(16),
- INVOKEDYNAMIC(18),
- INVALID(0);
-
- private final int tagCode;
-
- private Tag(int tagCode) {
- this.tagCode = tagCode;
- }
-
- private static Tag valueOf(byte v) {
- for (Tag tag : Tag.values()) {
- if (tag.tagCode == v) {
- return tag;
- }
- }
- throw new IllegalArgumentException("Unknown constant pool tag code " + v);
- }
- }
- //---------------------------------------------------------------------------
- // Internals only below this point
- //
-
- static {
- Reflection.registerFieldsToFilter(ConstantPool.class, new String[] { "constantPoolOop" });
- }
-
- // HotSpot-internal constant pool object (set by the VM, name known to the VM)
- private Object constantPoolOop;
-
- private native int getSize0 (Object constantPoolOop);
- private native Class<?> getClassAt0 (Object constantPoolOop, int index);
- private native Class<?> getClassAtIfLoaded0 (Object constantPoolOop, int index);
- private native int getClassRefIndexAt0 (Object constantPoolOop, int index);
- private native Member getMethodAt0 (Object constantPoolOop, int index);
- private native Member getMethodAtIfLoaded0(Object constantPoolOop, int index);
- private native Field getFieldAt0 (Object constantPoolOop, int index);
- private native Field getFieldAtIfLoaded0 (Object constantPoolOop, int index);
- private native String[] getMemberRefInfoAt0 (Object constantPoolOop, int index);
- private native int getNameAndTypeRefIndexAt0(Object constantPoolOop, int index);
- private native String[] getNameAndTypeRefInfoAt0(Object constantPoolOop, int index);
- private native int getIntAt0 (Object constantPoolOop, int index);
- private native long getLongAt0 (Object constantPoolOop, int index);
- private native float getFloatAt0 (Object constantPoolOop, int index);
- private native double getDoubleAt0 (Object constantPoolOop, int index);
- private native String getStringAt0 (Object constantPoolOop, int index);
- private native String getUTF8At0 (Object constantPoolOop, int index);
- private native byte getTagAt0 (Object constantPoolOop, int index);
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ConstructorAccessor.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.InvocationTargetException;
-
-/** This interface provides the declaration for
- java.lang.reflect.Constructor.invoke(). Each Constructor object is
- configured with a (possibly dynamically-generated) class which
- implements this interface. */
-
-public interface ConstructorAccessor {
- /** Matches specification in {@link java.lang.reflect.Constructor} */
- public Object newInstance(Object[] args)
- throws InstantiationException,
- IllegalArgumentException,
- InvocationTargetException;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ConstructorAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.InvocationTargetException;
-
-/** Package-private implementation of the ConstructorAccessor
- interface which has access to all classes and all fields,
- regardless of language restrictions. See MagicAccessorImpl. */
-
-abstract class ConstructorAccessorImpl extends MagicAccessorImpl
- implements ConstructorAccessor {
- /** Matches specification in {@link java.lang.reflect.Constructor} */
- public abstract Object newInstance(Object[] args)
- throws InstantiationException,
- IllegalArgumentException,
- InvocationTargetException;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/DelegatingConstructorAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.InvocationTargetException;
-
-/** Delegates its invocation to another ConstructorAccessorImpl and can
- change its delegate at run time. */
-
-class DelegatingConstructorAccessorImpl extends ConstructorAccessorImpl {
- private ConstructorAccessorImpl delegate;
-
- DelegatingConstructorAccessorImpl(ConstructorAccessorImpl delegate) {
- setDelegate(delegate);
- }
-
- public Object newInstance(Object[] args)
- throws InstantiationException,
- IllegalArgumentException,
- InvocationTargetException
- {
- return delegate.newInstance(args);
- }
-
- void setDelegate(ConstructorAccessorImpl delegate) {
- this.delegate = delegate;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/DelegatingMethodAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.InvocationTargetException;
-
-/** Delegates its invocation to another MethodAccessorImpl and can
- change its delegate at run time. */
-
-class DelegatingMethodAccessorImpl extends MethodAccessorImpl {
- private MethodAccessorImpl delegate;
-
- DelegatingMethodAccessorImpl(MethodAccessorImpl delegate) {
- setDelegate(delegate);
- }
-
- public Object invoke(Object obj, Object[] args)
- throws IllegalArgumentException, InvocationTargetException
- {
- return delegate.invoke(obj, args);
- }
-
- void setDelegate(MethodAccessorImpl delegate) {
- this.delegate = delegate;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/FieldAccessor.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-/** This interface provides the declarations for the accessor methods
- of java.lang.reflect.Field. Each Field object is configured with a
- (possibly dynamically-generated) class which implements this
- interface. */
-
-public interface FieldAccessor {
- /** Matches specification in {@link java.lang.reflect.Field} */
- public Object get(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public boolean getBoolean(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public byte getByte(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public char getChar(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public short getShort(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public int getInt(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public long getLong(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public float getFloat(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public double getDouble(Object obj) throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/FieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-/** Package-private implementation of the FieldAccessor interface
- which has access to all classes and all fields, regardless of
- language restrictions. See MagicAccessorImpl. */
-
-abstract class FieldAccessorImpl extends MagicAccessorImpl
- implements FieldAccessor {
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract Object get(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract boolean getBoolean(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract byte getByte(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract char getChar(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract short getShort(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract int getInt(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract long getLong(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract float getFloat(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract double getDouble(Object obj)
- throws IllegalArgumentException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException;
-
- /** Matches specification in {@link java.lang.reflect.Field} */
- public abstract void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/FieldInfo.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-/** NOTE: obsolete as of JDK 1.4 B75 and should be removed from the
- workspace (FIXME) */
-
-public class FieldInfo {
- // Set by the VM directly. Do not move these fields around or add
- // others before (or after) them without also modifying the VM's code.
- private String name;
- private String signature;
- private int modifiers;
- // This is compatible with the old reflection implementation's
- // "slot" value to allow jdk.internal.misc.Unsafe to work
- private int slot;
-
- // Not really necessary to provide a constructor since the VM
- // creates these directly
- FieldInfo() {
- }
-
- public String name() {
- return name;
- }
-
- /** This is in "external" format, i.e. having '.' as separator
- rather than '/' */
- public String signature() {
- return signature;
- }
-
- public int modifiers() {
- return modifiers;
- }
-
- public int slot() {
- return slot;
- }
-
- /** Convenience routine */
- public boolean isPublic() {
- return (Modifier.isPublic(modifiers()));
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/InstantiationExceptionConstructorAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-/** Throws an InstantiationException with given error message upon
- newInstance() call */
-
-class InstantiationExceptionConstructorAccessorImpl
- extends ConstructorAccessorImpl {
- private final String message;
-
- InstantiationExceptionConstructorAccessorImpl(String message) {
- this.message = message;
- }
-
- public Object newInstance(Object[] args)
- throws InstantiationException,
- IllegalArgumentException,
- InvocationTargetException
- {
- if (message == null) {
- throw new InstantiationException();
- }
- throw new InstantiationException(message);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/Label.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2001, 2011, 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.
- */
-
-package sun.reflect;
-
-import java.util.List;
-import java.util.ArrayList;
-
-/** Allows forward references in bytecode streams emitted by
- ClassFileAssembler. Assumes that the start of the method body is
- the first byte in the assembler's buffer. May be used at more than
- one branch site. */
-
-class Label {
- static class PatchInfo {
- PatchInfo(ClassFileAssembler asm,
- short instrBCI,
- short patchBCI,
- int stackDepth)
- {
- this.asm = asm;
- this.instrBCI = instrBCI;
- this.patchBCI = patchBCI;
- this.stackDepth = stackDepth;
- }
- // This won't work for more than one assembler anyway, so this is
- // unnecessary
- final ClassFileAssembler asm;
- final short instrBCI;
- final short patchBCI;
- final int stackDepth;
- }
- private final List<PatchInfo> patches = new ArrayList<>();
-
- public Label() {
- }
-
- void add(ClassFileAssembler asm,
- short instrBCI,
- short patchBCI,
- int stackDepth)
- {
- patches.add(new PatchInfo(asm, instrBCI, patchBCI, stackDepth));
- }
-
- public void bind() {
- for (PatchInfo patch : patches){
- short curBCI = patch.asm.getLength();
- short offset = (short) (curBCI - patch.instrBCI);
- patch.asm.emitShort(patch.patchBCI, offset);
- patch.asm.setStack(patch.stackDepth);
- }
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/LangReflectAccess.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.*;
-
-/** An interface which gives privileged packages Java-level access to
- internals of java.lang.reflect. */
-
-public interface LangReflectAccess {
- /** Creates a new java.lang.reflect.Field. Access checks as per
- java.lang.reflect.AccessibleObject are not overridden. */
- public Field newField(Class<?> declaringClass,
- String name,
- Class<?> type,
- int modifiers,
- int slot,
- String signature,
- byte[] annotations);
-
- /** Creates a new java.lang.reflect.Method. Access checks as per
- java.lang.reflect.AccessibleObject are not overridden. */
- public Method newMethod(Class<?> declaringClass,
- String name,
- Class<?>[] parameterTypes,
- Class<?> returnType,
- Class<?>[] checkedExceptions,
- int modifiers,
- int slot,
- String signature,
- byte[] annotations,
- byte[] parameterAnnotations,
- byte[] annotationDefault);
-
- /** Creates a new java.lang.reflect.Constructor. Access checks as
- per java.lang.reflect.AccessibleObject are not overridden. */
- public <T> Constructor<T> newConstructor(Class<T> declaringClass,
- Class<?>[] parameterTypes,
- Class<?>[] checkedExceptions,
- int modifiers,
- int slot,
- String signature,
- byte[] annotations,
- byte[] parameterAnnotations);
-
- /** Gets the MethodAccessor object for a java.lang.reflect.Method */
- public MethodAccessor getMethodAccessor(Method m);
-
- /** Sets the MethodAccessor object for a java.lang.reflect.Method */
- public void setMethodAccessor(Method m, MethodAccessor accessor);
-
- /** Gets the ConstructorAccessor object for a
- java.lang.reflect.Constructor */
- public ConstructorAccessor getConstructorAccessor(Constructor<?> c);
-
- /** Sets the ConstructorAccessor object for a
- java.lang.reflect.Constructor */
- public void setConstructorAccessor(Constructor<?> c,
- ConstructorAccessor accessor);
-
- /** Gets the byte[] that encodes TypeAnnotations on an Executable. */
- public byte[] getExecutableTypeAnnotationBytes(Executable ex);
-
- /** Gets the "slot" field from a Constructor (used for serialization) */
- public int getConstructorSlot(Constructor<?> c);
-
- /** Gets the "signature" field from a Constructor (used for serialization) */
- public String getConstructorSignature(Constructor<?> c);
-
- /** Gets the "annotations" field from a Constructor (used for serialization) */
- public byte[] getConstructorAnnotations(Constructor<?> c);
-
- /** Gets the "parameterAnnotations" field from a Constructor (used for serialization) */
- public byte[] getConstructorParameterAnnotations(Constructor<?> c);
-
- //
- // Copying routines, needed to quickly fabricate new Field,
- // Method, and Constructor objects from templates
- //
-
- /** Makes a "child" copy of a Method */
- public Method copyMethod(Method arg);
-
- /** Makes a copy of this non-root a Method */
- public Method leafCopyMethod(Method arg);
-
- /** Makes a "child" copy of a Field */
- public Field copyField(Field arg);
-
- /** Makes a "child" copy of a Constructor */
- public <T> Constructor<T> copyConstructor(Constructor<T> arg);
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/MagicAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-/** <P> MagicAccessorImpl (named for parity with FieldAccessorImpl and
- others, not because it actually implements an interface) is a
- marker class in the hierarchy. All subclasses of this class are
- "magically" granted access by the VM to otherwise inaccessible
- fields and methods of other classes. It is used to hold the code
- for dynamically-generated FieldAccessorImpl and MethodAccessorImpl
- subclasses. (Use of the word "unsafe" was avoided in this class's
- name to avoid confusion with {@link jdk.internal.misc.Unsafe}.) </P>
-
- <P> The bug fix for 4486457 also necessitated disabling
- verification for this class and all subclasses, as opposed to just
- SerializationConstructorAccessorImpl and subclasses, to avoid
- having to indicate to the VM which of these dynamically-generated
- stub classes were known to be able to pass the verifier. </P>
-
- <P> Do not change the name of this class without also changing the
- VM's code. </P> */
-
-class MagicAccessorImpl {
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/MethodAccessor.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.InvocationTargetException;
-
-/** This interface provides the declaration for
- java.lang.reflect.Method.invoke(). Each Method object is
- configured with a (possibly dynamically-generated) class which
- implements this interface.
-*/
-
-public interface MethodAccessor {
- /** Matches specification in {@link java.lang.reflect.Method} */
- public Object invoke(Object obj, Object[] args)
- throws IllegalArgumentException, InvocationTargetException;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/MethodAccessorGenerator.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,780 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-package sun.reflect;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/** Generator for sun.reflect.MethodAccessor and
- sun.reflect.ConstructorAccessor objects using bytecodes to
- implement reflection. A java.lang.reflect.Method or
- java.lang.reflect.Constructor object can delegate its invoke or
- newInstance method to an accessor using native code or to one
- generated by this class. (Methods and Constructors were merged
- together in this class to ensure maximum code sharing.) */
-
-class MethodAccessorGenerator extends AccessorGenerator {
-
- private static final short NUM_BASE_CPOOL_ENTRIES = (short) 12;
- // One for invoke() plus one for constructor
- private static final short NUM_METHODS = (short) 2;
- // Only used if forSerialization is true
- private static final short NUM_SERIALIZATION_CPOOL_ENTRIES = (short) 2;
-
- private static volatile int methodSymnum;
- private static volatile int constructorSymnum;
- private static volatile int serializationConstructorSymnum;
-
- private Class<?> declaringClass;
- private Class<?>[] parameterTypes;
- private Class<?> returnType;
- private boolean isConstructor;
- private boolean forSerialization;
-
- private short targetMethodRef;
- private short invokeIdx;
- private short invokeDescriptorIdx;
- // Constant pool index of CONSTANT_Class_info for first
- // non-primitive parameter type. Should be incremented by 2.
- private short nonPrimitiveParametersBaseIdx;
-
- MethodAccessorGenerator() {
- }
-
- /** This routine is not thread-safe */
- public MethodAccessor generateMethod(Class<?> declaringClass,
- String name,
- Class<?>[] parameterTypes,
- Class<?> returnType,
- Class<?>[] checkedExceptions,
- int modifiers)
- {
- return (MethodAccessor) generate(declaringClass,
- name,
- parameterTypes,
- returnType,
- checkedExceptions,
- modifiers,
- false,
- false,
- null);
- }
-
- /** This routine is not thread-safe */
- public ConstructorAccessor generateConstructor(Class<?> declaringClass,
- Class<?>[] parameterTypes,
- Class<?>[] checkedExceptions,
- int modifiers)
- {
- return (ConstructorAccessor) generate(declaringClass,
- "<init>",
- parameterTypes,
- Void.TYPE,
- checkedExceptions,
- modifiers,
- true,
- false,
- null);
- }
-
- /** This routine is not thread-safe */
- public SerializationConstructorAccessorImpl
- generateSerializationConstructor(Class<?> declaringClass,
- Class<?>[] parameterTypes,
- Class<?>[] checkedExceptions,
- int modifiers,
- Class<?> targetConstructorClass)
- {
- return (SerializationConstructorAccessorImpl)
- generate(declaringClass,
- "<init>",
- parameterTypes,
- Void.TYPE,
- checkedExceptions,
- modifiers,
- true,
- true,
- targetConstructorClass);
- }
-
- /** This routine is not thread-safe */
- private MagicAccessorImpl generate(final Class<?> declaringClass,
- String name,
- Class<?>[] parameterTypes,
- Class<?> returnType,
- Class<?>[] checkedExceptions,
- int modifiers,
- boolean isConstructor,
- boolean forSerialization,
- Class<?> serializationTargetClass)
- {
- ByteVector vec = ByteVectorFactory.create();
- asm = new ClassFileAssembler(vec);
- this.declaringClass = declaringClass;
- this.parameterTypes = parameterTypes;
- this.returnType = returnType;
- this.modifiers = modifiers;
- this.isConstructor = isConstructor;
- this.forSerialization = forSerialization;
-
- asm.emitMagicAndVersion();
-
- // Constant pool entries:
- // ( * = Boxing information: optional)
- // (+ = Shared entries provided by AccessorGenerator)
- // (^ = Only present if generating SerializationConstructorAccessor)
- // [UTF-8] [This class's name]
- // [CONSTANT_Class_info] for above
- // [UTF-8] "sun/reflect/{MethodAccessorImpl,ConstructorAccessorImpl,SerializationConstructorAccessorImpl}"
- // [CONSTANT_Class_info] for above
- // [UTF-8] [Target class's name]
- // [CONSTANT_Class_info] for above
- // ^ [UTF-8] [Serialization: Class's name in which to invoke constructor]
- // ^ [CONSTANT_Class_info] for above
- // [UTF-8] target method or constructor name
- // [UTF-8] target method or constructor signature
- // [CONSTANT_NameAndType_info] for above
- // [CONSTANT_Methodref_info or CONSTANT_InterfaceMethodref_info] for target method
- // [UTF-8] "invoke" or "newInstance"
- // [UTF-8] invoke or newInstance descriptor
- // [UTF-8] descriptor for type of non-primitive parameter 1
- // [CONSTANT_Class_info] for type of non-primitive parameter 1
- // ...
- // [UTF-8] descriptor for type of non-primitive parameter n
- // [CONSTANT_Class_info] for type of non-primitive parameter n
- // + [UTF-8] "java/lang/Exception"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/ClassCastException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/NullPointerException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/IllegalArgumentException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "java/lang/InvocationTargetException"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "<init>"
- // + [UTF-8] "()V"
- // + [CONSTANT_NameAndType_info] for above
- // + [CONSTANT_Methodref_info] for NullPointerException's constructor
- // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor
- // + [UTF-8] "(Ljava/lang/String;)V"
- // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/String;)V"
- // + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor taking a String
- // + [UTF-8] "(Ljava/lang/Throwable;)V"
- // + [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/Throwable;)V"
- // + [CONSTANT_Methodref_info] for InvocationTargetException's constructor
- // + [CONSTANT_Methodref_info] for "super()"
- // + [UTF-8] "java/lang/Object"
- // + [CONSTANT_Class_info] for above
- // + [UTF-8] "toString"
- // + [UTF-8] "()Ljava/lang/String;"
- // + [CONSTANT_NameAndType_info] for "toString()Ljava/lang/String;"
- // + [CONSTANT_Methodref_info] for Object's toString method
- // + [UTF-8] "Code"
- // + [UTF-8] "Exceptions"
- // * [UTF-8] "java/lang/Boolean"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(Z)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "booleanValue"
- // * [UTF-8] "()Z"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Byte"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(B)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "byteValue"
- // * [UTF-8] "()B"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Character"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(C)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "charValue"
- // * [UTF-8] "()C"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Double"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(D)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "doubleValue"
- // * [UTF-8] "()D"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Float"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(F)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "floatValue"
- // * [UTF-8] "()F"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Integer"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(I)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "intValue"
- // * [UTF-8] "()I"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Long"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(J)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "longValue"
- // * [UTF-8] "()J"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "java/lang/Short"
- // * [CONSTANT_Class_info] for above
- // * [UTF-8] "(S)V"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
- // * [UTF-8] "shortValue"
- // * [UTF-8] "()S"
- // * [CONSTANT_NameAndType_info] for above
- // * [CONSTANT_Methodref_info] for above
-
- short numCPEntries = NUM_BASE_CPOOL_ENTRIES + NUM_COMMON_CPOOL_ENTRIES;
- boolean usesPrimitives = usesPrimitiveTypes();
- if (usesPrimitives) {
- numCPEntries += NUM_BOXING_CPOOL_ENTRIES;
- }
- if (forSerialization) {
- numCPEntries += NUM_SERIALIZATION_CPOOL_ENTRIES;
- }
-
- // Add in variable-length number of entries to be able to describe
- // non-primitive parameter types and checked exceptions.
- numCPEntries += (short) (2 * numNonPrimitiveParameterTypes());
-
- asm.emitShort(add(numCPEntries, S1));
-
- final String generatedName = generateName(isConstructor, forSerialization);
- asm.emitConstantPoolUTF8(generatedName);
- asm.emitConstantPoolClass(asm.cpi());
- thisClass = asm.cpi();
- if (isConstructor) {
- if (forSerialization) {
- asm.emitConstantPoolUTF8
- ("sun/reflect/SerializationConstructorAccessorImpl");
- } else {
- asm.emitConstantPoolUTF8("sun/reflect/ConstructorAccessorImpl");
- }
- } else {
- asm.emitConstantPoolUTF8("sun/reflect/MethodAccessorImpl");
- }
- asm.emitConstantPoolClass(asm.cpi());
- superClass = asm.cpi();
- asm.emitConstantPoolUTF8(getClassName(declaringClass, false));
- asm.emitConstantPoolClass(asm.cpi());
- targetClass = asm.cpi();
- short serializationTargetClassIdx = (short) 0;
- if (forSerialization) {
- asm.emitConstantPoolUTF8(getClassName(serializationTargetClass, false));
- asm.emitConstantPoolClass(asm.cpi());
- serializationTargetClassIdx = asm.cpi();
- }
- asm.emitConstantPoolUTF8(name);
- asm.emitConstantPoolUTF8(buildInternalSignature());
- asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
- if (isInterface()) {
- asm.emitConstantPoolInterfaceMethodref(targetClass, asm.cpi());
- } else {
- if (forSerialization) {
- asm.emitConstantPoolMethodref(serializationTargetClassIdx, asm.cpi());
- } else {
- asm.emitConstantPoolMethodref(targetClass, asm.cpi());
- }
- }
- targetMethodRef = asm.cpi();
- if (isConstructor) {
- asm.emitConstantPoolUTF8("newInstance");
- } else {
- asm.emitConstantPoolUTF8("invoke");
- }
- invokeIdx = asm.cpi();
- if (isConstructor) {
- asm.emitConstantPoolUTF8("([Ljava/lang/Object;)Ljava/lang/Object;");
- } else {
- asm.emitConstantPoolUTF8
- ("(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;");
- }
- invokeDescriptorIdx = asm.cpi();
-
- // Output class information for non-primitive parameter types
- nonPrimitiveParametersBaseIdx = add(asm.cpi(), S2);
- for (int i = 0; i < parameterTypes.length; i++) {
- Class<?> c = parameterTypes[i];
- if (!isPrimitive(c)) {
- asm.emitConstantPoolUTF8(getClassName(c, false));
- asm.emitConstantPoolClass(asm.cpi());
- }
- }
-
- // Entries common to FieldAccessor, MethodAccessor and ConstructorAccessor
- emitCommonConstantPoolEntries();
-
- // Boxing entries
- if (usesPrimitives) {
- emitBoxingContantPoolEntries();
- }
-
- if (asm.cpi() != numCPEntries) {
- throw new InternalError("Adjust this code (cpi = " + asm.cpi() +
- ", numCPEntries = " + numCPEntries + ")");
- }
-
- // Access flags
- asm.emitShort(ACC_PUBLIC);
-
- // This class
- asm.emitShort(thisClass);
-
- // Superclass
- asm.emitShort(superClass);
-
- // Interfaces count and interfaces
- asm.emitShort(S0);
-
- // Fields count and fields
- asm.emitShort(S0);
-
- // Methods count and methods
- asm.emitShort(NUM_METHODS);
-
- emitConstructor();
- emitInvoke();
-
- // Additional attributes (none)
- asm.emitShort(S0);
-
- // Load class
- vec.trim();
- final byte[] bytes = vec.getData();
- // Note: the class loader is the only thing that really matters
- // here -- it's important to get the generated code into the
- // same namespace as the target class. Since the generated code
- // is privileged anyway, the protection domain probably doesn't
- // matter.
- return AccessController.doPrivileged(
- new PrivilegedAction<MagicAccessorImpl>() {
- public MagicAccessorImpl run() {
- try {
- return (MagicAccessorImpl)
- ClassDefiner.defineClass
- (generatedName,
- bytes,
- 0,
- bytes.length,
- declaringClass.getClassLoader()).newInstance();
- } catch (InstantiationException | IllegalAccessException e) {
- throw new InternalError(e);
- }
- }
- });
- }
-
- /** This emits the code for either invoke() or newInstance() */
- private void emitInvoke() {
- // NOTE that this code will only handle 65535 parameters since we
- // use the sipush instruction to get the array index on the
- // operand stack.
- if (parameterTypes.length > 65535) {
- throw new InternalError("Can't handle more than 65535 parameters");
- }
-
- // Generate code into fresh code buffer
- ClassFileAssembler cb = new ClassFileAssembler();
- if (isConstructor) {
- // 1 incoming argument
- cb.setMaxLocals(2);
- } else {
- // 2 incoming arguments
- cb.setMaxLocals(3);
- }
-
- short illegalArgStartPC = 0;
-
- if (isConstructor) {
- // Instantiate target class before continuing
- // new <target class type>
- // dup
- cb.opc_new(targetClass);
- cb.opc_dup();
- } else {
- // Setup before iterating down argument list
- if (isPrimitive(returnType)) {
- // new <boxing type for primitive type>
- // dup
- // ... (see below:)
- // invokespecial <constructor for boxing type for primitive type>
- // areturn
- cb.opc_new(indexForPrimitiveType(returnType));
- cb.opc_dup();
- }
-
- // Get target object on operand stack if necessary.
-
- // We need to do an explicit null check here; we won't see
- // NullPointerExceptions from the invoke bytecode, since it's
- // covered by an exception handler.
- if (!isStatic()) {
- // aload_1
- // ifnonnull <checkcast label>
- // new <NullPointerException>
- // dup
- // invokespecial <NullPointerException ctor>
- // athrow
- // <checkcast label:>
- // aload_1
- // checkcast <target class's type>
- cb.opc_aload_1();
- Label l = new Label();
- cb.opc_ifnonnull(l);
- cb.opc_new(nullPointerClass);
- cb.opc_dup();
- cb.opc_invokespecial(nullPointerCtorIdx, 0, 0);
- cb.opc_athrow();
- l.bind();
- illegalArgStartPC = cb.getLength();
- cb.opc_aload_1();
- cb.opc_checkcast(targetClass);
- }
- }
-
- // Have to check length of incoming array and throw
- // IllegalArgumentException if not correct. A concession to the
- // JCK (isn't clearly specified in the spec): we allow null in the
- // case where the argument list is zero length.
- // if no-arg:
- // aload_2 | aload_1 (Method | Constructor)
- // ifnull <success label>
- // aload_2 | aload_1
- // arraylength
- // sipush <num parameter types>
- // if_icmpeq <success label>
- // new <IllegalArgumentException>
- // dup
- // invokespecial <IllegalArgumentException ctor>
- // athrow
- // <success label:>
- Label successLabel = new Label();
- if (parameterTypes.length == 0) {
- if (isConstructor) {
- cb.opc_aload_1();
- } else {
- cb.opc_aload_2();
- }
- cb.opc_ifnull(successLabel);
- }
- if (isConstructor) {
- cb.opc_aload_1();
- } else {
- cb.opc_aload_2();
- }
- cb.opc_arraylength();
- cb.opc_sipush((short) parameterTypes.length);
- cb.opc_if_icmpeq(successLabel);
- cb.opc_new(illegalArgumentClass);
- cb.opc_dup();
- cb.opc_invokespecial(illegalArgumentCtorIdx, 0, 0);
- cb.opc_athrow();
- successLabel.bind();
-
- // Iterate through incoming actual parameters, ensuring that each
- // is compatible with the formal parameter type, and pushing the
- // actual on the operand stack (unboxing and widening if necessary).
-
- short paramTypeCPIdx = nonPrimitiveParametersBaseIdx;
- Label nextParamLabel = null;
- byte count = 1; // both invokeinterface opcode's "count" as well as
- // num args of other invoke bytecodes
- for (int i = 0; i < parameterTypes.length; i++) {
- Class<?> paramType = parameterTypes[i];
- count += (byte) typeSizeInStackSlots(paramType);
- if (nextParamLabel != null) {
- nextParamLabel.bind();
- nextParamLabel = null;
- }
- // aload_2 | aload_1
- // sipush <index>
- // aaload
- if (isConstructor) {
- cb.opc_aload_1();
- } else {
- cb.opc_aload_2();
- }
- cb.opc_sipush((short) i);
- cb.opc_aaload();
- if (isPrimitive(paramType)) {
- // Unboxing code.
- // Put parameter into temporary local variable
- // astore_3 | astore_2
- if (isConstructor) {
- cb.opc_astore_2();
- } else {
- cb.opc_astore_3();
- }
-
- // repeat for all possible widening conversions:
- // aload_3 | aload_2
- // instanceof <primitive boxing type>
- // ifeq <next unboxing label>
- // aload_3 | aload_2
- // checkcast <primitive boxing type> // Note: this is "redundant",
- // // but necessary for the verifier
- // invokevirtual <unboxing method>
- // <widening conversion bytecode, if necessary>
- // goto <next parameter label>
- // <next unboxing label:> ...
- // last unboxing label:
- // new <IllegalArgumentException>
- // dup
- // invokespecial <IllegalArgumentException ctor>
- // athrow
-
- Label l = null; // unboxing label
- nextParamLabel = new Label();
-
- for (int j = 0; j < primitiveTypes.length; j++) {
- Class<?> c = primitiveTypes[j];
- if (canWidenTo(c, paramType)) {
- if (l != null) {
- l.bind();
- }
- // Emit checking and unboxing code for this type
- if (isConstructor) {
- cb.opc_aload_2();
- } else {
- cb.opc_aload_3();
- }
- cb.opc_instanceof(indexForPrimitiveType(c));
- l = new Label();
- cb.opc_ifeq(l);
- if (isConstructor) {
- cb.opc_aload_2();
- } else {
- cb.opc_aload_3();
- }
- cb.opc_checkcast(indexForPrimitiveType(c));
- cb.opc_invokevirtual(unboxingMethodForPrimitiveType(c),
- 0,
- typeSizeInStackSlots(c));
- emitWideningBytecodeForPrimitiveConversion(cb,
- c,
- paramType);
- cb.opc_goto(nextParamLabel);
- }
- }
-
- if (l == null) {
- throw new InternalError
- ("Must have found at least identity conversion");
- }
-
- // Fell through; given object is null or invalid. According to
- // the spec, we can throw IllegalArgumentException for both of
- // these cases.
-
- l.bind();
- cb.opc_new(illegalArgumentClass);
- cb.opc_dup();
- cb.opc_invokespecial(illegalArgumentCtorIdx, 0, 0);
- cb.opc_athrow();
- } else {
- // Emit appropriate checkcast
- cb.opc_checkcast(paramTypeCPIdx);
- paramTypeCPIdx = add(paramTypeCPIdx, S2);
- // Fall through to next argument
- }
- }
- // Bind last goto if present
- if (nextParamLabel != null) {
- nextParamLabel.bind();
- }
-
- short invokeStartPC = cb.getLength();
-
- // OK, ready to perform the invocation.
- if (isConstructor) {
- cb.opc_invokespecial(targetMethodRef, count, 0);
- } else {
- if (isStatic()) {
- cb.opc_invokestatic(targetMethodRef,
- count,
- typeSizeInStackSlots(returnType));
- } else {
- if (isInterface()) {
- if (isPrivate()) {
- cb.opc_invokespecial(targetMethodRef, count, 0);
- } else {
- cb.opc_invokeinterface(targetMethodRef,
- count,
- count,
- typeSizeInStackSlots(returnType));
- }
- } else {
- cb.opc_invokevirtual(targetMethodRef,
- count,
- typeSizeInStackSlots(returnType));
- }
- }
- }
-
- short invokeEndPC = cb.getLength();
-
- if (!isConstructor) {
- // Box return value if necessary
- if (isPrimitive(returnType)) {
- cb.opc_invokestatic(boxingMethodForPrimitiveType(returnType),
- typeSizeInStackSlots(returnType),
- 0);
- } else if (returnType == Void.TYPE) {
- cb.opc_aconst_null();
- }
- }
- cb.opc_areturn();
-
- // We generate two exception handlers; one which is responsible
- // for catching ClassCastException and NullPointerException and
- // throwing IllegalArgumentException, and the other which catches
- // all java/lang/Throwable objects thrown from the target method
- // and wraps them in InvocationTargetExceptions.
-
- short classCastHandler = cb.getLength();
-
- // ClassCast, etc. exception handler
- cb.setStack(1);
- cb.opc_invokespecial(toStringIdx, 0, 1);
- cb.opc_new(illegalArgumentClass);
- cb.opc_dup_x1();
- cb.opc_swap();
- cb.opc_invokespecial(illegalArgumentStringCtorIdx, 1, 0);
- cb.opc_athrow();
-
- short invocationTargetHandler = cb.getLength();
-
- // InvocationTargetException exception handler
- cb.setStack(1);
- cb.opc_new(invocationTargetClass);
- cb.opc_dup_x1();
- cb.opc_swap();
- cb.opc_invokespecial(invocationTargetCtorIdx, 1, 0);
- cb.opc_athrow();
-
- // Generate exception table. We cover the entire code sequence
- // with an exception handler which catches ClassCastException and
- // converts it into an IllegalArgumentException.
-
- ClassFileAssembler exc = new ClassFileAssembler();
-
- exc.emitShort(illegalArgStartPC); // start PC
- exc.emitShort(invokeStartPC); // end PC
- exc.emitShort(classCastHandler); // handler PC
- exc.emitShort(classCastClass); // catch type
-
- exc.emitShort(illegalArgStartPC); // start PC
- exc.emitShort(invokeStartPC); // end PC
- exc.emitShort(classCastHandler); // handler PC
- exc.emitShort(nullPointerClass); // catch type
-
- exc.emitShort(invokeStartPC); // start PC
- exc.emitShort(invokeEndPC); // end PC
- exc.emitShort(invocationTargetHandler); // handler PC
- exc.emitShort(throwableClass); // catch type
-
- emitMethod(invokeIdx, cb.getMaxLocals(), cb, exc,
- new short[] { invocationTargetClass });
- }
-
- private boolean usesPrimitiveTypes() {
- // We need to emit boxing/unboxing constant pool information if
- // the method takes a primitive type for any of its parameters or
- // returns a primitive value (except void)
- if (returnType.isPrimitive()) {
- return true;
- }
- for (int i = 0; i < parameterTypes.length; i++) {
- if (parameterTypes[i].isPrimitive()) {
- return true;
- }
- }
- return false;
- }
-
- private int numNonPrimitiveParameterTypes() {
- int num = 0;
- for (int i = 0; i < parameterTypes.length; i++) {
- if (!parameterTypes[i].isPrimitive()) {
- ++num;
- }
- }
- return num;
- }
-
- private boolean isInterface() {
- return declaringClass.isInterface();
- }
-
- private String buildInternalSignature() {
- StringBuilder sb = new StringBuilder();
- sb.append("(");
- for (int i = 0; i < parameterTypes.length; i++) {
- sb.append(getClassName(parameterTypes[i], true));
- }
- sb.append(")");
- sb.append(getClassName(returnType, true));
- return sb.toString();
- }
-
- private static synchronized String generateName(boolean isConstructor,
- boolean forSerialization)
- {
- if (isConstructor) {
- if (forSerialization) {
- int num = ++serializationConstructorSymnum;
- return "sun/reflect/GeneratedSerializationConstructorAccessor" + num;
- } else {
- int num = ++constructorSymnum;
- return "sun/reflect/GeneratedConstructorAccessor" + num;
- }
- } else {
- int num = ++methodSymnum;
- return "sun/reflect/GeneratedMethodAccessor" + num;
- }
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/MethodAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.InvocationTargetException;
-
-/** <P> Package-private implementation of the MethodAccessor interface
- which has access to all classes and all fields, regardless of
- language restrictions. See MagicAccessor. </P>
-
- <P> This class is known to the VM; do not change its name without
- also changing the VM's code. </P>
-
- <P> NOTE: ALL methods of subclasses are skipped during security
- walks up the stack. The assumption is that the only such methods
- that will persistently show up on the stack are the implementing
- methods for java.lang.reflect.Method.invoke(). </P>
-*/
-
-abstract class MethodAccessorImpl extends MagicAccessorImpl
- implements MethodAccessor {
- /** Matches specification in {@link java.lang.reflect.Method} */
- public abstract Object invoke(Object obj, Object[] args)
- throws IllegalArgumentException, InvocationTargetException;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/NativeConstructorAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-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 */
-
-class NativeConstructorAccessorImpl extends ConstructorAccessorImpl {
- private final Constructor<?> c;
- private DelegatingConstructorAccessorImpl parent;
- private int numInvocations;
-
- NativeConstructorAccessorImpl(Constructor<?> c) {
- this.c = c;
- }
-
- public Object newInstance(Object[] args)
- throws InstantiationException,
- IllegalArgumentException,
- InvocationTargetException
- {
- // 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(),
- c.getParameterTypes(),
- c.getExceptionTypes(),
- c.getModifiers());
- parent.setDelegate(acc);
- }
-
- return newInstance0(c, args);
- }
-
- void setParent(DelegatingConstructorAccessorImpl parent) {
- this.parent = parent;
- }
-
- private static native Object newInstance0(Constructor<?> c, Object[] args)
- throws InstantiationException,
- IllegalArgumentException,
- InvocationTargetException;
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/NativeMethodAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-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 */
-
-class NativeMethodAccessorImpl extends MethodAccessorImpl {
- private final Method method;
- private DelegatingMethodAccessorImpl parent;
- private int numInvocations;
-
- NativeMethodAccessorImpl(Method method) {
- this.method = method;
- }
-
- public Object invoke(Object obj, Object[] args)
- throws IllegalArgumentException, InvocationTargetException
- {
- // 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(),
- method.getName(),
- method.getParameterTypes(),
- method.getReturnType(),
- method.getExceptionTypes(),
- method.getModifiers());
- parent.setDelegate(acc);
- }
-
- return invoke0(method, obj, args);
- }
-
- void setParent(DelegatingMethodAccessorImpl parent) {
- this.parent = parent;
- }
-
- private static native Object invoke0(Method m, Object obj, Object[] args);
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/Reflection.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,425 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-package sun.reflect;
-
-
-import java.lang.reflect.*;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import jdk.internal.HotSpotIntrinsicCandidate;
-import jdk.internal.misc.VM;
-
-/** Common utility routines used by both java.lang and
- java.lang.reflect */
-
-public class Reflection {
-
- /** Used to filter out fields and methods from certain classes from public
- view, where they are sensitive or they may contain VM-internal objects.
- These Maps are updated very rarely. Rather than synchronize on
- each access, we use copy-on-write */
- private static volatile Map<Class<?>,String[]> fieldFilterMap;
- private static volatile Map<Class<?>,String[]> methodFilterMap;
-
- static {
- Map<Class<?>,String[]> map = new HashMap<Class<?>,String[]>();
- map.put(Reflection.class,
- new String[] {"fieldFilterMap", "methodFilterMap"});
- map.put(System.class, new String[] {"security"});
- map.put(Class.class, new String[] {"classLoader"});
- fieldFilterMap = map;
-
- methodFilterMap = new HashMap<>();
- }
-
- /** Returns the class of the caller of the method calling this method,
- ignoring frames associated with java.lang.reflect.Method.invoke()
- and its implementation. */
- @CallerSensitive
- @HotSpotIntrinsicCandidate
- public static native Class<?> getCallerClass();
-
- /**
- * @deprecated This method will be removed in JDK 9.
- * This method is a private JDK API and retained temporarily for
- * existing code to run until a replacement API is defined.
- */
- @Deprecated
- public static native Class<?> getCallerClass(int depth);
-
- /** Retrieves the access flags written to the class file. For
- inner classes these flags may differ from those returned by
- Class.getModifiers(), which searches the InnerClasses
- attribute to find the source-level access flags. This is used
- instead of Class.getModifiers() for run-time access checks due
- to compatibility reasons; see 4471811. Only the values of the
- low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
- valid. */
- @HotSpotIntrinsicCandidate
- public static native int getClassAccessFlags(Class<?> c);
-
-
- public static void ensureMemberAccess(Class<?> currentClass,
- Class<?> memberClass,
- Object target,
- int modifiers)
- throws IllegalAccessException
- {
- if (currentClass == null || memberClass == null) {
- throw new InternalError();
- }
-
- if (!verifyMemberAccess(currentClass, memberClass, target, modifiers)) {
- throwIllegalAccessException(currentClass, memberClass, target, modifiers);
- }
- }
-
- public static boolean verifyMemberAccess(Class<?> currentClass,
- // Declaring class of field
- // or method
- Class<?> memberClass,
- // May be NULL in case of statics
- Object target,
- int modifiers)
- {
- // Verify that currentClass can access a field, method, or
- // constructor of memberClass, where that member's access bits are
- // "modifiers".
-
- boolean gotIsSameClassPackage = false;
- boolean isSameClassPackage = false;
-
- if (currentClass == memberClass) {
- // Always succeeds
- return true;
- }
-
- if (!verifyModuleAccess(currentClass, memberClass)) {
- return false;
- }
-
- if (!Modifier.isPublic(getClassAccessFlags(memberClass))) {
- isSameClassPackage = isSameClassPackage(currentClass, memberClass);
- gotIsSameClassPackage = true;
- if (!isSameClassPackage) {
- return false;
- }
- }
-
- // At this point we know that currentClass can access memberClass.
-
- if (Modifier.isPublic(modifiers)) {
- return true;
- }
-
- boolean successSoFar = false;
-
- if (Modifier.isProtected(modifiers)) {
- // See if currentClass is a subclass of memberClass
- if (isSubclassOf(currentClass, memberClass)) {
- successSoFar = true;
- }
- }
-
- if (!successSoFar && !Modifier.isPrivate(modifiers)) {
- if (!gotIsSameClassPackage) {
- isSameClassPackage = isSameClassPackage(currentClass,
- memberClass);
- gotIsSameClassPackage = true;
- }
-
- if (isSameClassPackage) {
- successSoFar = true;
- }
- }
-
- if (!successSoFar) {
- return false;
- }
-
- if (Modifier.isProtected(modifiers)) {
- // Additional test for protected members: JLS 6.6.2
- Class<?> targetClass = (target == null ? memberClass : target.getClass());
- if (targetClass != currentClass) {
- if (!gotIsSameClassPackage) {
- isSameClassPackage = isSameClassPackage(currentClass, memberClass);
- gotIsSameClassPackage = true;
- }
- if (!isSameClassPackage) {
- if (!isSubclassOf(targetClass, currentClass)) {
- return false;
- }
- }
- }
- }
-
- return true;
- }
-
- /**
- * Returns {@code true} if memberClass's's module exports memberClass's
- * package to currentClass's module.
- */
- public static boolean verifyModuleAccess(Class<?> currentClass,
- Class<?> memberClass) {
- return verifyModuleAccess(currentClass.getModule(), memberClass);
- }
-
- public static boolean verifyModuleAccess(Module currentModule, Class<?> memberClass) {
- Module memberModule = memberClass.getModule();
-
- // module may be null during startup (initLevel 0)
- if (currentModule == memberModule)
- return true; // same module (named or unnamed)
-
- // memberClass may be primitive or array class
- Class<?> c = memberClass;
- while (c.isArray()) {
- c = c.getComponentType();
- }
- if (c.isPrimitive())
- return true;
-
- // check that memberModule exports the package to currentModule
- return memberModule.isExported(c.getPackageName(), currentModule);
- }
-
- /**
- * Returns true if two classes in the same package.
- */
- private static boolean isSameClassPackage(Class<?> c1, Class<?> c2) {
- if (c1.getClassLoader() != c2.getClassLoader())
- return false;
- while (c1.isArray())
- c1 = c1.getComponentType();
- while (c2.isArray())
- c2 = c2.getComponentType();
- return Objects.equals(c1.getPackageName(), c2.getPackageName());
- }
-
- static boolean isSubclassOf(Class<?> queryClass,
- Class<?> ofClass)
- {
- while (queryClass != null) {
- if (queryClass == ofClass) {
- return true;
- }
- queryClass = queryClass.getSuperclass();
- }
- return false;
- }
-
- // fieldNames must contain only interned Strings
- public static synchronized void registerFieldsToFilter(Class<?> containingClass,
- String ... fieldNames) {
- fieldFilterMap =
- registerFilter(fieldFilterMap, containingClass, fieldNames);
- }
-
- // methodNames must contain only interned Strings
- public static synchronized void registerMethodsToFilter(Class<?> containingClass,
- String ... methodNames) {
- methodFilterMap =
- registerFilter(methodFilterMap, containingClass, methodNames);
- }
-
- private static Map<Class<?>,String[]> registerFilter(Map<Class<?>,String[]> map,
- Class<?> containingClass, String ... names) {
- if (map.get(containingClass) != null) {
- throw new IllegalArgumentException
- ("Filter already registered: " + containingClass);
- }
- map = new HashMap<Class<?>,String[]>(map);
- map.put(containingClass, names);
- return map;
- }
-
- public static Field[] filterFields(Class<?> containingClass,
- Field[] fields) {
- if (fieldFilterMap == null) {
- // Bootstrapping
- return fields;
- }
- return (Field[])filter(fields, fieldFilterMap.get(containingClass));
- }
-
- public static Method[] filterMethods(Class<?> containingClass, Method[] methods) {
- if (methodFilterMap == null) {
- // Bootstrapping
- return methods;
- }
- return (Method[])filter(methods, methodFilterMap.get(containingClass));
- }
-
- private static Member[] filter(Member[] members, String[] filteredNames) {
- if ((filteredNames == null) || (members.length == 0)) {
- return members;
- }
- int numNewMembers = 0;
- for (Member member : members) {
- boolean shouldSkip = false;
- for (String filteredName : filteredNames) {
- if (member.getName() == filteredName) {
- shouldSkip = true;
- break;
- }
- }
- if (!shouldSkip) {
- ++numNewMembers;
- }
- }
- Member[] newMembers =
- (Member[])Array.newInstance(members[0].getClass(), numNewMembers);
- int destIdx = 0;
- for (Member member : members) {
- boolean shouldSkip = false;
- for (String filteredName : filteredNames) {
- if (member.getName() == filteredName) {
- shouldSkip = true;
- break;
- }
- }
- if (!shouldSkip) {
- newMembers[destIdx++] = member;
- }
- }
- return newMembers;
- }
-
- /**
- * Tests if the given method is caller-sensitive and the declaring class
- * is defined by either the bootstrap class loader or platform class loader.
- */
- public static boolean isCallerSensitive(Method m) {
- final ClassLoader loader = m.getDeclaringClass().getClassLoader();
- if (VM.isSystemDomainLoader(loader) || isExtClassLoader(loader)) {
- return m.isAnnotationPresent(CallerSensitive.class);
- }
- return false;
- }
-
- private static boolean isExtClassLoader(ClassLoader loader) {
- ClassLoader cl = ClassLoader.getSystemClassLoader();
- while (cl != null) {
- if (cl.getParent() == null && cl == loader) {
- return true;
- }
- cl = cl.getParent();
- }
- return false;
- }
-
-
- // true to print a stack trace when IAE is thrown
- private static volatile boolean printStackWhenAccessFails;
-
- // true if printStackWhenAccessFails has been initialized
- private static volatile boolean printStackWhenAccessFailsSet;
-
- private static void printStackTraceIfNeeded(Throwable e) {
- if (!printStackWhenAccessFailsSet && VM.initLevel() >= 1) {
- // can't use method reference here, might be too early in startup
- PrivilegedAction<Boolean> pa = new PrivilegedAction<Boolean>() {
- public Boolean run() {
- String s;
- s = System.getProperty("sun.reflect.debugModuleAccessChecks");
- return (s != null && !s.equalsIgnoreCase("false"));
- }
- };
- printStackWhenAccessFails = AccessController.doPrivileged(pa);
- printStackWhenAccessFailsSet = true;
- }
- if (printStackWhenAccessFails) {
- e.printStackTrace();
- }
- }
-
- /**
- * Throws IllegalAccessException with the an exception message based on
- * the access that is denied.
- */
- private static void throwIllegalAccessException(Class<?> currentClass,
- Class<?> memberClass,
- Object target,
- int modifiers)
- throws IllegalAccessException
- {
- String currentSuffix = "";
- String memberSuffix = "";
- Module m1 = currentClass.getModule();
- if (m1.isNamed())
- currentSuffix = " (in " + m1 + ")";
- Module m2 = memberClass.getModule();
- if (m2.isNamed())
- memberSuffix = " (in " + m2 + ")";
-
- Class<?> c = memberClass;
- while (c.isArray()) {
- c = c.getComponentType();
- }
- String memberPackageName = c.getPackageName();
-
- String msg = currentClass + currentSuffix + " cannot access ";
- if (m2.isExported(memberPackageName, m1)) {
-
- // module access okay so include the modifiers in the message
- msg += "a member of " + memberClass + memberSuffix +
- " with modifiers \"" + Modifier.toString(modifiers) + "\"";
-
- } else {
- // module access failed
- msg += memberClass + memberSuffix+ " because "
- + m2 + " does not export " + memberPackageName;
- if (m2.isNamed()) msg += " to " + m1;
- }
-
- throwIllegalAccessException(msg);
- }
-
- /**
- * Throws IllegalAccessException with the given exception message.
- */
- public static void throwIllegalAccessException(String msg)
- throws IllegalAccessException
- {
- IllegalAccessException e = new IllegalAccessException(msg);
- printStackTraceIfNeeded(e);
- throw e;
- }
-
- /**
- * Throws InaccessibleObjectException with the given exception message.
- */
- public static void throwInaccessibleObjectException(String msg) {
- InaccessibleObjectException e = new InaccessibleObjectException(msg);
- printStackTraceIfNeeded(e);
- throw e;
- }
-
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/ReflectionFactory.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,432 +0,0 @@
-/*
- * 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
- * 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Executable;
-import java.lang.reflect.Method;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
-import java.security.AccessController;
-import java.security.Permission;
-import java.security.PrivilegedAction;
-import sun.reflect.misc.ReflectUtil;
-
-/** <P> The master factory for all reflective objects, both those in
- java.lang.reflect (Fields, Methods, Constructors) as well as their
- delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
- </P>
-
- <P> The methods in this class are extremely unsafe and can cause
- subversion of both the language and the verifier. For this reason,
- they are all instance methods, and access to the constructor of
- this factory is guarded by a security check, in similar style to
- {@link jdk.internal.misc.Unsafe}. </P>
-*/
-
-public class ReflectionFactory {
-
- private static boolean initted = false;
- private static final Permission reflectionFactoryAccessPerm
- = new RuntimePermission("reflectionFactoryAccess");
- private static final ReflectionFactory soleInstance = new ReflectionFactory();
- // Provides access to package-private mechanisms in java.lang.reflect
- private static volatile LangReflectAccess langReflectAccess;
-
- //
- // "Inflation" mechanism. Loading bytecodes to implement
- // Method.invoke() and Constructor.newInstance() currently costs
- // 3-4x more than an invocation via native code for the first
- // invocation (though subsequent invocations have been benchmarked
- // to be over 20x faster). Unfortunately this cost increases
- // startup time for certain applications that use reflection
- // intensively (but only once per class) to bootstrap themselves.
- // To avoid this penalty we reuse the existing JVM entry points
- // for the first few invocations of Methods and Constructors and
- // then switch to the bytecode-based implementations.
- //
- // Package-private to be accessible to NativeMethodAccessorImpl
- // and NativeConstructorAccessorImpl
- private static boolean noInflation = false;
- private static int inflationThreshold = 15;
-
- private ReflectionFactory() {
- }
-
- /**
- * A convenience class for acquiring the capability to instantiate
- * reflective objects. Use this instead of a raw call to {@link
- * #getReflectionFactory} in order to avoid being limited by the
- * permissions of your callers.
- *
- * <p>An instance of this class can be used as the argument of
- * <code>AccessController.doPrivileged</code>.
- */
- public static final class GetReflectionFactoryAction
- implements PrivilegedAction<ReflectionFactory> {
- public ReflectionFactory run() {
- return getReflectionFactory();
- }
- }
-
- /**
- * Provides the caller with the capability to instantiate reflective
- * objects.
- *
- * <p> First, if there is a security manager, its
- * <code>checkPermission</code> method is called with a {@link
- * java.lang.RuntimePermission} with target
- * <code>"reflectionFactoryAccess"</code>. This may result in a
- * security exception.
- *
- * <p> The returned <code>ReflectionFactory</code> object should be
- * carefully guarded by the caller, since it can be used to read and
- * write private data and invoke private methods, as well as to load
- * unverified bytecodes. It must never be passed to untrusted code.
- *
- * @exception SecurityException if a security manager exists and its
- * <code>checkPermission</code> method doesn't allow
- * access to the RuntimePermission "reflectionFactoryAccess". */
- public static ReflectionFactory getReflectionFactory() {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- // TO DO: security.checkReflectionFactoryAccess();
- security.checkPermission(reflectionFactoryAccessPerm);
- }
- return soleInstance;
- }
-
- //--------------------------------------------------------------------------
- //
- // Routines used by java.lang.reflect
- //
- //
-
- /** Called only by java.lang.reflect.Modifier's static initializer */
- public void setLangReflectAccess(LangReflectAccess access) {
- langReflectAccess = access;
- }
-
- /**
- * Note: this routine can cause the declaring class for the field
- * be initialized and therefore must not be called until the
- * first get/set of this field.
- * @param field the field
- * @param override true if caller has overridden accessibility
- */
- public FieldAccessor newFieldAccessor(Field field, boolean override) {
- checkInitted();
- return UnsafeFieldAccessorFactory.newFieldAccessor(field, override);
- }
-
- public MethodAccessor newMethodAccessor(Method method) {
- checkInitted();
-
- if (noInflation && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
- return new MethodAccessorGenerator().
- generateMethod(method.getDeclaringClass(),
- method.getName(),
- method.getParameterTypes(),
- method.getReturnType(),
- method.getExceptionTypes(),
- method.getModifiers());
- } else {
- NativeMethodAccessorImpl acc =
- new NativeMethodAccessorImpl(method);
- DelegatingMethodAccessorImpl res =
- new DelegatingMethodAccessorImpl(acc);
- acc.setParent(res);
- return res;
- }
- }
-
- public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
- checkInitted();
-
- Class<?> declaringClass = c.getDeclaringClass();
- if (Modifier.isAbstract(declaringClass.getModifiers())) {
- return new InstantiationExceptionConstructorAccessorImpl(null);
- }
- if (declaringClass == Class.class) {
- return new InstantiationExceptionConstructorAccessorImpl
- ("Can not instantiate java.lang.Class");
- }
- // Bootstrapping issue: since we use Class.newInstance() in
- // the ConstructorAccessor generation process, we have to
- // break the cycle here.
- if (Reflection.isSubclassOf(declaringClass,
- ConstructorAccessorImpl.class)) {
- return new BootstrapConstructorAccessorImpl(c);
- }
-
- if (noInflation && !ReflectUtil.isVMAnonymousClass(c.getDeclaringClass())) {
- return new MethodAccessorGenerator().
- generateConstructor(c.getDeclaringClass(),
- c.getParameterTypes(),
- c.getExceptionTypes(),
- c.getModifiers());
- } else {
- NativeConstructorAccessorImpl acc =
- new NativeConstructorAccessorImpl(c);
- DelegatingConstructorAccessorImpl res =
- new DelegatingConstructorAccessorImpl(acc);
- acc.setParent(res);
- return res;
- }
- }
-
- //--------------------------------------------------------------------------
- //
- // Routines used by java.lang
- //
- //
-
- /** Creates a new java.lang.reflect.Field. Access checks as per
- java.lang.reflect.AccessibleObject are not overridden. */
- public Field newField(Class<?> declaringClass,
- String name,
- Class<?> type,
- int modifiers,
- int slot,
- String signature,
- byte[] annotations)
- {
- return langReflectAccess().newField(declaringClass,
- name,
- type,
- modifiers,
- slot,
- signature,
- annotations);
- }
-
- /** Creates a new java.lang.reflect.Method. Access checks as per
- java.lang.reflect.AccessibleObject are not overridden. */
- public Method newMethod(Class<?> declaringClass,
- String name,
- Class<?>[] parameterTypes,
- Class<?> returnType,
- Class<?>[] checkedExceptions,
- int modifiers,
- int slot,
- String signature,
- byte[] annotations,
- byte[] parameterAnnotations,
- byte[] annotationDefault)
- {
- return langReflectAccess().newMethod(declaringClass,
- name,
- parameterTypes,
- returnType,
- checkedExceptions,
- modifiers,
- slot,
- signature,
- annotations,
- parameterAnnotations,
- annotationDefault);
- }
-
- /** Creates a new java.lang.reflect.Constructor. Access checks as
- per java.lang.reflect.AccessibleObject are not overridden. */
- public Constructor<?> newConstructor(Class<?> declaringClass,
- Class<?>[] parameterTypes,
- Class<?>[] checkedExceptions,
- int modifiers,
- int slot,
- String signature,
- byte[] annotations,
- byte[] parameterAnnotations)
- {
- return langReflectAccess().newConstructor(declaringClass,
- parameterTypes,
- checkedExceptions,
- modifiers,
- slot,
- signature,
- annotations,
- parameterAnnotations);
- }
-
- /** Gets the MethodAccessor object for a java.lang.reflect.Method */
- public MethodAccessor getMethodAccessor(Method m) {
- return langReflectAccess().getMethodAccessor(m);
- }
-
- /** Sets the MethodAccessor object for a java.lang.reflect.Method */
- public void setMethodAccessor(Method m, MethodAccessor accessor) {
- langReflectAccess().setMethodAccessor(m, accessor);
- }
-
- /** Gets the ConstructorAccessor object for a
- java.lang.reflect.Constructor */
- public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
- return langReflectAccess().getConstructorAccessor(c);
- }
-
- /** Sets the ConstructorAccessor object for a
- java.lang.reflect.Constructor */
- public void setConstructorAccessor(Constructor<?> c,
- ConstructorAccessor accessor)
- {
- langReflectAccess().setConstructorAccessor(c, accessor);
- }
-
- /** Makes a copy of the passed method. The returned method is a
- "child" of the passed one; see the comments in Method.java for
- details. */
- public Method copyMethod(Method arg) {
- return langReflectAccess().copyMethod(arg);
- }
-
- /** Makes a copy of the passed method. The returned method is NOT
- * a "child" but a "sibling" of the Method in arg. Should only be
- * used on non-root methods. */
- public Method leafCopyMethod(Method arg) {
- return langReflectAccess().leafCopyMethod(arg);
- }
-
-
- /** Makes a copy of the passed field. The returned field is a
- "child" of the passed one; see the comments in Field.java for
- details. */
- public Field copyField(Field arg) {
- return langReflectAccess().copyField(arg);
- }
-
- /** Makes a copy of the passed constructor. The returned
- constructor is a "child" of the passed one; see the comments
- in Constructor.java for details. */
- public <T> Constructor<T> copyConstructor(Constructor<T> arg) {
- return langReflectAccess().copyConstructor(arg);
- }
-
- /** Gets the byte[] that encodes TypeAnnotations on an executable.
- */
- public byte[] getExecutableTypeAnnotationBytes(Executable ex) {
- return langReflectAccess().getExecutableTypeAnnotationBytes(ex);
- }
-
- //--------------------------------------------------------------------------
- //
- // Routines used by serialization
- //
- //
-
- public Constructor<?> newConstructorForSerialization
- (Class<?> classToInstantiate, Constructor<?> constructorToCall)
- {
- // Fast path
- if (constructorToCall.getDeclaringClass() == classToInstantiate) {
- return constructorToCall;
- }
-
- ConstructorAccessor acc = new MethodAccessorGenerator().
- generateSerializationConstructor(classToInstantiate,
- constructorToCall.getParameterTypes(),
- constructorToCall.getExceptionTypes(),
- constructorToCall.getModifiers(),
- constructorToCall.getDeclaringClass());
- Constructor<?> c = newConstructor(constructorToCall.getDeclaringClass(),
- constructorToCall.getParameterTypes(),
- constructorToCall.getExceptionTypes(),
- constructorToCall.getModifiers(),
- langReflectAccess().
- getConstructorSlot(constructorToCall),
- langReflectAccess().
- getConstructorSignature(constructorToCall),
- langReflectAccess().
- getConstructorAnnotations(constructorToCall),
- langReflectAccess().
- getConstructorParameterAnnotations(constructorToCall));
- setConstructorAccessor(c, acc);
- return c;
- }
-
- //--------------------------------------------------------------------------
- //
- // Internals only below this point
- //
-
- static int inflationThreshold() {
- return inflationThreshold;
- }
-
- /** We have to defer full initialization of this class until after
- the static initializer is run since java.lang.reflect.Method's
- static initializer (more properly, that for
- java.lang.reflect.AccessibleObject) causes this class's to be
- run, before the system properties are set up. */
- private static void checkInitted() {
- if (initted) return;
- AccessController.doPrivileged(
- new PrivilegedAction<>() {
- public Void run() {
- // Tests to ensure the system properties table is fully
- // initialized. This is needed because reflection code is
- // called very early in the initialization process (before
- // command-line arguments have been parsed and therefore
- // these user-settable properties installed.) We assume that
- // if System.out is non-null then the System class has been
- // fully initialized and that the bulk of the startup code
- // has been run.
-
- if (System.out == null) {
- // java.lang.System not yet fully initialized
- return null;
- }
-
- String val = System.getProperty("sun.reflect.noInflation");
- if (val != null && val.equals("true")) {
- noInflation = true;
- }
-
- val = System.getProperty("sun.reflect.inflationThreshold");
- if (val != null) {
- try {
- inflationThreshold = Integer.parseInt(val);
- } catch (NumberFormatException e) {
- throw new RuntimeException("Unable to parse property sun.reflect.inflationThreshold", e);
- }
- }
-
- initted = true;
- return null;
- }
- });
- }
-
- private static LangReflectAccess langReflectAccess() {
- if (langReflectAccess == null) {
- // Call a static method to get class java.lang.reflect.Modifier
- // initialized. Its static initializer will cause
- // setLangReflectAccess() to be called from the context of the
- // java.lang.reflect package.
- Modifier.isPublic(Modifier.PUBLIC);
- }
- return langReflectAccess;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/SerializationConstructorAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-/** <P> Java serialization (in java.io) expects to be able to
- instantiate a class and invoke a no-arg constructor of that
- class's first non-Serializable superclass. This is not a valid
- operation according to the VM specification; one can not (for
- classes A and B, where B is a subclass of A) write "new B;
- invokespecial A()" without getting a verification error. </P>
-
- <P> In all other respects, the bytecode-based reflection framework
- can be reused for this purpose. This marker class was originally
- known to the VM and verification disabled for it and all
- subclasses, but the bug fix for 4486457 necessitated disabling
- verification for all of the dynamically-generated bytecodes
- associated with reflection. This class has been left in place to
- make future debugging easier. </P> */
-
-abstract class SerializationConstructorAccessorImpl
- extends ConstructorAccessorImpl {
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/SignatureIterator.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2001, 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.
- */
-
-package sun.reflect;
-
-/** Assists in iterating down a method's signature */
-
-public class SignatureIterator {
- private final String sig;
- private int idx;
-
- public SignatureIterator(String sig) {
- this.sig = sig;
- reset();
- }
-
- public void reset() {
- idx = 1;
- }
-
- public boolean atEnd() {
- return sig.charAt(idx) == ')';
- }
-
- public String next() {
- if (atEnd()) return null;
- char c = sig.charAt(idx);
- if (c != '[' && c != 'L') {
- ++idx;
- return new String(new char[] { c });
- }
- // Walk forward to end of entry
- int endIdx = idx;
- if (c == '[') {
- while ((c = sig.charAt(endIdx)) == '[') {
- endIdx++;
- }
- }
-
- if (c == 'L') {
- while (sig.charAt(endIdx) != ';') {
- endIdx++;
- }
- }
-
- int beginIdx = idx;
- idx = endIdx + 1;
- return sig.substring(beginIdx, idx);
- }
-
- /** Should only be called when atEnd() is true. Does not change
- state of iterator. */
- public String returnType() {
- if (!atEnd()) {
- throw new InternalError("Illegal use of SignatureIterator");
- }
- return sig.substring(idx + 1, sig.length());
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UTF8.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2001, 2011, 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.
- */
-
-package sun.reflect;
-
-/** It is necessary to use a "bootstrap" UTF-8 encoder for encoding
- constant pool entries because the character set converters rely on
- Class.newInstance(). */
-
-class UTF8 {
- // This encoder is not quite correct. It does not handle surrogate pairs.
- static byte[] encode(String str) {
- int len = str.length();
- byte[] res = new byte[utf8Length(str)];
- int utf8Idx = 0;
- try {
- for (int i = 0; i < len; i++) {
- int c = str.charAt(i) & 0xFFFF;
- if (c >= 0x0001 && c <= 0x007F) {
- res[utf8Idx++] = (byte) c;
- } else if (c == 0x0000 ||
- (c >= 0x0080 && c <= 0x07FF)) {
- res[utf8Idx++] = (byte) (0xC0 + (c >> 6));
- res[utf8Idx++] = (byte) (0x80 + (c & 0x3F));
- } else {
- res[utf8Idx++] = (byte) (0xE0 + (c >> 12));
- res[utf8Idx++] = (byte) (0x80 + ((c >> 6) & 0x3F));
- res[utf8Idx++] = (byte) (0x80 + (c & 0x3F));
- }
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new InternalError
- ("Bug in sun.reflect bootstrap UTF-8 encoder", e);
- }
- return res;
- }
-
- private static int utf8Length(String str) {
- int len = str.length();
- int utf8Len = 0;
- for (int i = 0; i < len; i++) {
- int c = str.charAt(i) & 0xFFFF;
- if (c >= 0x0001 && c <= 0x007F) {
- utf8Len += 1;
- } else if (c == 0x0000 ||
- (c >= 0x0080 && c <= 0x07FF)) {
- utf8Len += 2;
- } else {
- utf8Len += 3;
- }
- }
- return utf8Len;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeBooleanFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeBooleanFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeBooleanFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Boolean.valueOf(getBoolean(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getBoolean(obj, fieldOffset);
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Boolean) {
- unsafe.putBoolean(obj, fieldOffset, ((Boolean) value).booleanValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(z);
- }
- unsafe.putBoolean(obj, fieldOffset, z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeByteFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeByteFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeByteFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Byte.valueOf(getByte(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getByte(obj, fieldOffset);
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putByte(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(b);
- }
- unsafe.putByte(obj, fieldOffset, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeCharacterFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeCharacterFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeCharacterFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Character.valueOf(getChar(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getChar(obj, fieldOffset);
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Character) {
- unsafe.putChar(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(c);
- }
- unsafe.putChar(obj, fieldOffset, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeDoubleFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeDoubleFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeDoubleFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Double.valueOf(getDouble(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getDouble(obj, fieldOffset);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putDouble(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putDouble(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putDouble(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putDouble(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putDouble(obj, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putDouble(obj, fieldOffset, ((Float) value).floatValue());
- return;
- }
- if (value instanceof Double) {
- unsafe.putDouble(obj, fieldOffset, ((Double) value).doubleValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(d);
- }
- unsafe.putDouble(obj, fieldOffset, d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeFieldAccessorFactory.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) 2001, 2011, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-class UnsafeFieldAccessorFactory {
- static FieldAccessor newFieldAccessor(Field field, boolean override) {
- Class<?> type = field.getType();
- boolean isStatic = Modifier.isStatic(field.getModifiers());
- boolean isFinal = Modifier.isFinal(field.getModifiers());
- boolean isVolatile = Modifier.isVolatile(field.getModifiers());
- boolean isQualified = isFinal || isVolatile;
- boolean isReadOnly = isFinal && (isStatic || !override);
- if (isStatic) {
- // This code path does not guarantee that the field's
- // declaring class has been initialized, but it must be
- // before performing reflective operations.
- UnsafeFieldAccessorImpl.unsafe.ensureClassInitialized(field.getDeclaringClass());
-
- if (!isQualified) {
- if (type == Boolean.TYPE) {
- return new UnsafeStaticBooleanFieldAccessorImpl(field);
- } else if (type == Byte.TYPE) {
- return new UnsafeStaticByteFieldAccessorImpl(field);
- } else if (type == Short.TYPE) {
- return new UnsafeStaticShortFieldAccessorImpl(field);
- } else if (type == Character.TYPE) {
- return new UnsafeStaticCharacterFieldAccessorImpl(field);
- } else if (type == Integer.TYPE) {
- return new UnsafeStaticIntegerFieldAccessorImpl(field);
- } else if (type == Long.TYPE) {
- return new UnsafeStaticLongFieldAccessorImpl(field);
- } else if (type == Float.TYPE) {
- return new UnsafeStaticFloatFieldAccessorImpl(field);
- } else if (type == Double.TYPE) {
- return new UnsafeStaticDoubleFieldAccessorImpl(field);
- } else {
- return new UnsafeStaticObjectFieldAccessorImpl(field);
- }
- } else {
- if (type == Boolean.TYPE) {
- return new UnsafeQualifiedStaticBooleanFieldAccessorImpl(field, isReadOnly);
- } else if (type == Byte.TYPE) {
- return new UnsafeQualifiedStaticByteFieldAccessorImpl(field, isReadOnly);
- } else if (type == Short.TYPE) {
- return new UnsafeQualifiedStaticShortFieldAccessorImpl(field, isReadOnly);
- } else if (type == Character.TYPE) {
- return new UnsafeQualifiedStaticCharacterFieldAccessorImpl(field, isReadOnly);
- } else if (type == Integer.TYPE) {
- return new UnsafeQualifiedStaticIntegerFieldAccessorImpl(field, isReadOnly);
- } else if (type == Long.TYPE) {
- return new UnsafeQualifiedStaticLongFieldAccessorImpl(field, isReadOnly);
- } else if (type == Float.TYPE) {
- return new UnsafeQualifiedStaticFloatFieldAccessorImpl(field, isReadOnly);
- } else if (type == Double.TYPE) {
- return new UnsafeQualifiedStaticDoubleFieldAccessorImpl(field, isReadOnly);
- } else {
- return new UnsafeQualifiedStaticObjectFieldAccessorImpl(field, isReadOnly);
- }
- }
- } else {
- if (!isQualified) {
- if (type == Boolean.TYPE) {
- return new UnsafeBooleanFieldAccessorImpl(field);
- } else if (type == Byte.TYPE) {
- return new UnsafeByteFieldAccessorImpl(field);
- } else if (type == Short.TYPE) {
- return new UnsafeShortFieldAccessorImpl(field);
- } else if (type == Character.TYPE) {
- return new UnsafeCharacterFieldAccessorImpl(field);
- } else if (type == Integer.TYPE) {
- return new UnsafeIntegerFieldAccessorImpl(field);
- } else if (type == Long.TYPE) {
- return new UnsafeLongFieldAccessorImpl(field);
- } else if (type == Float.TYPE) {
- return new UnsafeFloatFieldAccessorImpl(field);
- } else if (type == Double.TYPE) {
- return new UnsafeDoubleFieldAccessorImpl(field);
- } else {
- return new UnsafeObjectFieldAccessorImpl(field);
- }
- } else {
- if (type == Boolean.TYPE) {
- return new UnsafeQualifiedBooleanFieldAccessorImpl(field, isReadOnly);
- } else if (type == Byte.TYPE) {
- return new UnsafeQualifiedByteFieldAccessorImpl(field, isReadOnly);
- } else if (type == Short.TYPE) {
- return new UnsafeQualifiedShortFieldAccessorImpl(field, isReadOnly);
- } else if (type == Character.TYPE) {
- return new UnsafeQualifiedCharacterFieldAccessorImpl(field, isReadOnly);
- } else if (type == Integer.TYPE) {
- return new UnsafeQualifiedIntegerFieldAccessorImpl(field, isReadOnly);
- } else if (type == Long.TYPE) {
- return new UnsafeQualifiedLongFieldAccessorImpl(field, isReadOnly);
- } else if (type == Float.TYPE) {
- return new UnsafeQualifiedFloatFieldAccessorImpl(field, isReadOnly);
- } else if (type == Double.TYPE) {
- return new UnsafeQualifiedDoubleFieldAccessorImpl(field, isReadOnly);
- } else {
- return new UnsafeQualifiedObjectFieldAccessorImpl(field, isReadOnly);
- }
- }
- }
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2001, 2011, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import jdk.internal.misc.Unsafe;
-
-/** Base class for jdk.internal.misc.Unsafe-based FieldAccessors. The
- observation is that there are only nine types of fields from the
- standpoint of reflection code: the eight primitive types and
- Object. Using class Unsafe instead of generated bytecodes saves
- memory and loading time for the dynamically-generated
- FieldAccessors. */
-
-abstract class UnsafeFieldAccessorImpl extends FieldAccessorImpl {
- static final Unsafe unsafe = Unsafe.getUnsafe();
-
- protected final Field field;
- protected final long fieldOffset;
- protected final boolean isFinal;
-
- UnsafeFieldAccessorImpl(Field field) {
- this.field = field;
- if (Modifier.isStatic(field.getModifiers()))
- fieldOffset = unsafe.staticFieldOffset(field);
- else
- fieldOffset = unsafe.objectFieldOffset(field);
- isFinal = Modifier.isFinal(field.getModifiers());
- }
-
- protected void ensureObj(Object o) {
- // NOTE: will throw NullPointerException, as specified, if o is null
- if (!field.getDeclaringClass().isAssignableFrom(o.getClass())) {
- throwSetIllegalArgumentException(o);
- }
- }
-
- private String getQualifiedFieldName() {
- return field.getDeclaringClass().getName() + "." +field.getName();
- }
-
- protected IllegalArgumentException newGetIllegalArgumentException(String type) {
- return new IllegalArgumentException(
- "Attempt to get "+field.getType().getName()+" field \"" +
- getQualifiedFieldName() + "\" with illegal data type conversion to "+type
- );
- }
-
- protected void throwFinalFieldIllegalAccessException(String attemptedType,
- String attemptedValue)
- throws IllegalAccessException {
- throw new IllegalAccessException(getSetMessage(attemptedType, attemptedValue));
-
- }
- protected void throwFinalFieldIllegalAccessException(Object o) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException(o != null ? o.getClass().getName() : "", "");
- }
-
- protected void throwFinalFieldIllegalAccessException(boolean z) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("boolean", Boolean.toString(z));
- }
-
- protected void throwFinalFieldIllegalAccessException(char b) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("char", Character.toString(b));
- }
-
- protected void throwFinalFieldIllegalAccessException(byte b) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("byte", Byte.toString(b));
- }
-
- protected void throwFinalFieldIllegalAccessException(short b) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("short", Short.toString(b));
- }
-
- protected void throwFinalFieldIllegalAccessException(int i) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("int", Integer.toString(i));
- }
-
- protected void throwFinalFieldIllegalAccessException(long i) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("long", Long.toString(i));
- }
-
- protected void throwFinalFieldIllegalAccessException(float f) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("float", Float.toString(f));
- }
-
- protected void throwFinalFieldIllegalAccessException(double f) throws IllegalAccessException {
- throwFinalFieldIllegalAccessException("double", Double.toString(f));
- }
-
- protected IllegalArgumentException newGetBooleanIllegalArgumentException() {
- return newGetIllegalArgumentException("boolean");
- }
-
- protected IllegalArgumentException newGetByteIllegalArgumentException() {
- return newGetIllegalArgumentException("byte");
- }
-
- protected IllegalArgumentException newGetCharIllegalArgumentException() {
- return newGetIllegalArgumentException("char");
- }
-
- protected IllegalArgumentException newGetShortIllegalArgumentException() {
- return newGetIllegalArgumentException("short");
- }
-
- protected IllegalArgumentException newGetIntIllegalArgumentException() {
- return newGetIllegalArgumentException("int");
- }
-
- protected IllegalArgumentException newGetLongIllegalArgumentException() {
- return newGetIllegalArgumentException("long");
- }
-
- protected IllegalArgumentException newGetFloatIllegalArgumentException() {
- return newGetIllegalArgumentException("float");
- }
-
- protected IllegalArgumentException newGetDoubleIllegalArgumentException() {
- return newGetIllegalArgumentException("double");
- }
-
- protected String getSetMessage(String attemptedType, String attemptedValue) {
- String err = "Can not set";
- if (Modifier.isStatic(field.getModifiers()))
- err += " static";
- if (isFinal)
- err += " final";
- err += " " + field.getType().getName() + " field " + getQualifiedFieldName() + " to ";
- if (attemptedValue.length() > 0) {
- err += "(" + attemptedType + ")" + attemptedValue;
- } else {
- if (attemptedType.length() > 0)
- err += attemptedType;
- else
- err += "null value";
- }
- return err;
- }
-
- protected void throwSetIllegalArgumentException(String attemptedType,
- String attemptedValue) {
- throw new IllegalArgumentException(getSetMessage(attemptedType,attemptedValue));
- }
-
- protected void throwSetIllegalArgumentException(Object o) {
- throwSetIllegalArgumentException(o != null ? o.getClass().getName() : "", "");
- }
-
- protected void throwSetIllegalArgumentException(boolean b) {
- throwSetIllegalArgumentException("boolean", Boolean.toString(b));
- }
-
- protected void throwSetIllegalArgumentException(byte b) {
- throwSetIllegalArgumentException("byte", Byte.toString(b));
- }
-
- protected void throwSetIllegalArgumentException(char c) {
- throwSetIllegalArgumentException("char", Character.toString(c));
- }
-
- protected void throwSetIllegalArgumentException(short s) {
- throwSetIllegalArgumentException("short", Short.toString(s));
- }
-
- protected void throwSetIllegalArgumentException(int i) {
- throwSetIllegalArgumentException("int", Integer.toString(i));
- }
-
- protected void throwSetIllegalArgumentException(long l) {
- throwSetIllegalArgumentException("long", Long.toString(l));
- }
-
- protected void throwSetIllegalArgumentException(float f) {
- throwSetIllegalArgumentException("float", Float.toString(f));
- }
-
- protected void throwSetIllegalArgumentException(double d) {
- throwSetIllegalArgumentException("double", Double.toString(d));
- }
-
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeFloatFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeFloatFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeFloatFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Float.valueOf(getFloat(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getFloat(obj, fieldOffset);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getFloat(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putFloat(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putFloat(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putFloat(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putFloat(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putFloat(obj, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putFloat(obj, fieldOffset, ((Float) value).floatValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(f);
- }
- unsafe.putFloat(obj, fieldOffset, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeIntegerFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeIntegerFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeIntegerFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Integer.valueOf(getInt(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getInt(obj, fieldOffset);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putInt(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putInt(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putInt(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putInt(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(i);
- }
- unsafe.putInt(obj, fieldOffset, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeLongFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,156 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeLongFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeLongFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Long.valueOf(getLong(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getLong(obj, fieldOffset);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putLong(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putLong(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putLong(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putLong(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putLong(obj, fieldOffset, ((Long) value).longValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(l);
- }
- unsafe.putLong(obj, fieldOffset, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeObjectFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeObjectFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeObjectFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getObject(obj, fieldOffset);
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value != null) {
- if (!field.getType().isAssignableFrom(value.getClass())) {
- throwSetIllegalArgumentException(value);
- }
- }
- unsafe.putObject(obj, fieldOffset, value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedBooleanFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedBooleanFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedBooleanFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Boolean.valueOf(getBoolean(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getBooleanVolatile(obj, fieldOffset);
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Boolean) {
- unsafe.putBooleanVolatile(obj, fieldOffset, ((Boolean) value).booleanValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(z);
- }
- unsafe.putBooleanVolatile(obj, fieldOffset, z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedByteFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedByteFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedByteFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Byte.valueOf(getByte(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getByteVolatile(obj, fieldOffset);
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putByteVolatile(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(b);
- }
- unsafe.putByteVolatile(obj, fieldOffset, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedCharacterFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedCharacterFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedCharacterFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Character.valueOf(getChar(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getCharVolatile(obj, fieldOffset);
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Character) {
- unsafe.putCharVolatile(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(c);
- }
- unsafe.putCharVolatile(obj, fieldOffset, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedDoubleFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedDoubleFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedDoubleFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Double.valueOf(getDouble(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getDoubleVolatile(obj, fieldOffset);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putDoubleVolatile(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putDoubleVolatile(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putDoubleVolatile(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putDoubleVolatile(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putDoubleVolatile(obj, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putDoubleVolatile(obj, fieldOffset, ((Float) value).floatValue());
- return;
- }
- if (value instanceof Double) {
- unsafe.putDoubleVolatile(obj, fieldOffset, ((Double) value).doubleValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(d);
- }
- unsafe.putDoubleVolatile(obj, fieldOffset, d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2004, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import jdk.internal.misc.Unsafe;
-
-/**
- * Base class for jdk.internal.misc.Unsafe-based FieldAccessors for fields with
- * final or volatile qualifiers. These differ from unqualified
- * versions in that (1) they check for read-only status (2) they use
- * the volatile forms of Unsafe get/put methods. (When accessed via
- * reflection, finals act as slightly "lighter" forms of volatiles. So
- * the volatile forms are heavier than necessary in terms of
- * underlying reordering rules and memory barriers, but preserve
- * correctness.)
- */
-
-abstract class UnsafeQualifiedFieldAccessorImpl
- extends UnsafeFieldAccessorImpl
-{
- protected final boolean isReadOnly;
-
- UnsafeQualifiedFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field);
- this.isReadOnly = isReadOnly;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedFloatFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedFloatFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedFloatFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Float.valueOf(getFloat(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getFloatVolatile(obj, fieldOffset);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getFloat(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putFloatVolatile(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putFloatVolatile(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putFloatVolatile(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putFloatVolatile(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putFloatVolatile(obj, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putFloatVolatile(obj, fieldOffset, ((Float) value).floatValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(f);
- }
- unsafe.putFloatVolatile(obj, fieldOffset, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedIntegerFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,154 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedIntegerFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedIntegerFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Integer.valueOf(getInt(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getIntVolatile(obj, fieldOffset);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putIntVolatile(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putIntVolatile(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putIntVolatile(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putIntVolatile(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(i);
- }
- unsafe.putIntVolatile(obj, fieldOffset, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedLongFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedLongFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedLongFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Long.valueOf(getLong(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getLongVolatile(obj, fieldOffset);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putLongVolatile(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putLongVolatile(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putLongVolatile(obj, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putLongVolatile(obj, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putLongVolatile(obj, fieldOffset, ((Long) value).longValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(l);
- }
- unsafe.putLongVolatile(obj, fieldOffset, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedObjectFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedObjectFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedObjectFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getObjectVolatile(obj, fieldOffset);
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value != null) {
- if (!field.getType().isAssignableFrom(value.getClass())) {
- throwSetIllegalArgumentException(value);
- }
- }
- unsafe.putObjectVolatile(obj, fieldOffset, value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedShortFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedShortFieldAccessorImpl
- extends UnsafeQualifiedFieldAccessorImpl
-{
- UnsafeQualifiedShortFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Short.valueOf(getShort(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getShortVolatile(obj, fieldOffset);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putShortVolatile(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putShortVolatile(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setShort(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(s);
- }
- unsafe.putShortVolatile(obj, fieldOffset, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticBooleanFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticBooleanFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticBooleanFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Boolean.valueOf(getBoolean(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- return unsafe.getBooleanVolatile(base, fieldOffset);
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Boolean) {
- unsafe.putBooleanVolatile(base, fieldOffset, ((Boolean) value).booleanValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(z);
- }
- unsafe.putBooleanVolatile(base, fieldOffset, z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticByteFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticByteFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticByteFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Byte.valueOf(getByte(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- return unsafe.getByteVolatile(base, fieldOffset);
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putByteVolatile(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(b);
- }
- unsafe.putByteVolatile(base, fieldOffset, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticCharacterFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticCharacterFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticCharacterFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Character.valueOf(getChar(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- return unsafe.getCharVolatile(base, fieldOffset);
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Character) {
- unsafe.putCharVolatile(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(c);
- }
- unsafe.putCharVolatile(base, fieldOffset, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticDoubleFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticDoubleFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticDoubleFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Double.valueOf(getDouble(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return unsafe.getDoubleVolatile(base, fieldOffset);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putDoubleVolatile(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putDoubleVolatile(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putDoubleVolatile(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putDoubleVolatile(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putDoubleVolatile(base, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putDoubleVolatile(base, fieldOffset, ((Float) value).floatValue());
- return;
- }
- if (value instanceof Double) {
- unsafe.putDoubleVolatile(base, fieldOffset, ((Double) value).doubleValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(d);
- }
- unsafe.putDoubleVolatile(base, fieldOffset, d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2004, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.security.AccessController;
-import jdk.internal.misc.Unsafe;
-
-/** Base class for jdk.internal.misc.Unsafe-based FieldAccessors for final or
- static volatile fields. */
-
-abstract class UnsafeQualifiedStaticFieldAccessorImpl
- extends UnsafeStaticFieldAccessorImpl
-{
- protected final boolean isReadOnly;
-
- UnsafeQualifiedStaticFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field);
- this.isReadOnly = isReadOnly;
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticFloatFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticFloatFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticFloatFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Float.valueOf(getFloat(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return unsafe.getFloatVolatile(base, fieldOffset);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getFloat(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putFloatVolatile(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putFloatVolatile(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putFloatVolatile(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putFloatVolatile(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putFloatVolatile(base, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putFloatVolatile(base, fieldOffset, ((Float) value).floatValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(f);
- }
- unsafe.putFloatVolatile(base, fieldOffset, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticIntegerFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,151 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticIntegerFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticIntegerFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Integer.valueOf(getInt(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return unsafe.getIntVolatile(base, fieldOffset);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putIntVolatile(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putIntVolatile(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putIntVolatile(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putIntVolatile(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(i);
- }
- unsafe.putIntVolatile(base, fieldOffset, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticLongFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticLongFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticLongFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Long.valueOf(getLong(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return unsafe.getLongVolatile(base, fieldOffset);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putLongVolatile(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putLongVolatile(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putLongVolatile(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putLongVolatile(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putLongVolatile(base, fieldOffset, ((Long) value).longValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(l);
- }
- unsafe.putLongVolatile(base, fieldOffset, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticObjectFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticObjectFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticObjectFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return unsafe.getObjectVolatile(base, fieldOffset);
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value != null) {
- if (!field.getType().isAssignableFrom(value.getClass())) {
- throwSetIllegalArgumentException(value);
- }
- }
- unsafe.putObjectVolatile(base, fieldOffset, value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeQualifiedStaticShortFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,143 +0,0 @@
-/*
- * Copyright (c) 2004, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeQualifiedStaticShortFieldAccessorImpl
- extends UnsafeQualifiedStaticFieldAccessorImpl
-{
- UnsafeQualifiedStaticShortFieldAccessorImpl(Field field, boolean isReadOnly) {
- super(field, isReadOnly);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Short.valueOf(getShort(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- return unsafe.getShortVolatile(base, fieldOffset);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putShortVolatile(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putShortVolatile(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setShort(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isReadOnly) {
- throwFinalFieldIllegalAccessException(s);
- }
- unsafe.putShortVolatile(base, fieldOffset, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeShortFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeShortFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- UnsafeShortFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Short.valueOf(getShort(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- ensureObj(obj);
- return unsafe.getShort(obj, fieldOffset);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putShort(obj, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putShort(obj, fieldOffset, ((Short) value).shortValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setShort(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- ensureObj(obj);
- if (isFinal) {
- throwFinalFieldIllegalAccessException(s);
- }
- unsafe.putShort(obj, fieldOffset, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticBooleanFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticBooleanFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticBooleanFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Boolean.valueOf(getBoolean(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- return unsafe.getBoolean(base, fieldOffset);
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Boolean) {
- unsafe.putBoolean(base, fieldOffset, ((Boolean) value).booleanValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(z);
- }
- unsafe.putBoolean(base, fieldOffset, z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticByteFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticByteFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticByteFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Byte.valueOf(getByte(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- return unsafe.getByte(base, fieldOffset);
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getByte(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putByte(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(b);
- }
- unsafe.putByte(base, fieldOffset, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticCharacterFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticCharacterFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticCharacterFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Character.valueOf(getChar(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- return unsafe.getChar(base, fieldOffset);
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getChar(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Character) {
- unsafe.putChar(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(c);
- }
- unsafe.putChar(base, fieldOffset, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticDoubleFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticDoubleFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticDoubleFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Double.valueOf(getDouble(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return unsafe.getDouble(base, fieldOffset);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putDouble(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putDouble(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putDouble(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putDouble(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putDouble(base, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putDouble(base, fieldOffset, ((Float) value).floatValue());
- return;
- }
- if (value instanceof Double) {
- unsafe.putDouble(base, fieldOffset, ((Double) value).doubleValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- setDouble(obj, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(d);
- }
- unsafe.putDouble(base, fieldOffset, d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2001, 2012, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.security.AccessController;
-import jdk.internal.misc.Unsafe;
-
-/** Base class for jdk.internal.misc.Unsafe-based FieldAccessors for static
- fields. The observation is that there are only nine types of
- fields from the standpoint of reflection code: the eight primitive
- types and Object. Using class Unsafe instead of generated
- bytecodes saves memory and loading time for the
- dynamically-generated FieldAccessors. */
-
-abstract class UnsafeStaticFieldAccessorImpl extends UnsafeFieldAccessorImpl {
- static {
- Reflection.registerFieldsToFilter(UnsafeStaticFieldAccessorImpl.class,
- new String[] { "base" });
- }
-
- protected final Object base; // base
-
- UnsafeStaticFieldAccessorImpl(Field field) {
- super(field);
- base = unsafe.staticFieldBase(field);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticFloatFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,157 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticFloatFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticFloatFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Float.valueOf(getFloat(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return unsafe.getFloat(base, fieldOffset);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getFloat(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putFloat(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putFloat(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putFloat(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putFloat(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putFloat(base, fieldOffset, ((Long) value).longValue());
- return;
- }
- if (value instanceof Float) {
- unsafe.putFloat(base, fieldOffset, ((Float) value).floatValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- setFloat(obj, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(f);
- }
- unsafe.putFloat(base, fieldOffset, f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticIntegerFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticIntegerFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticIntegerFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Integer.valueOf(getInt(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return unsafe.getInt(base, fieldOffset);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getInt(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putInt(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putInt(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putInt(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putInt(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setInt(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(i);
- }
- unsafe.putInt(base, fieldOffset, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticLongFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticLongFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticLongFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Long.valueOf(getLong(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return unsafe.getLong(base, fieldOffset);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getLong(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putLong(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putLong(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- if (value instanceof Character) {
- unsafe.putLong(base, fieldOffset, ((Character) value).charValue());
- return;
- }
- if (value instanceof Integer) {
- unsafe.putLong(base, fieldOffset, ((Integer) value).intValue());
- return;
- }
- if (value instanceof Long) {
- unsafe.putLong(base, fieldOffset, ((Long) value).longValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- setLong(obj, i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(l);
- }
- unsafe.putLong(base, fieldOffset, l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticObjectFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticObjectFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticObjectFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return unsafe.getObject(base, fieldOffset);
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- throw newGetShortIllegalArgumentException();
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- throw newGetIntIllegalArgumentException();
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- throw newGetLongIllegalArgumentException();
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- throw newGetFloatIllegalArgumentException();
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- throw newGetDoubleIllegalArgumentException();
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value != null) {
- if (!field.getType().isAssignableFrom(value.getClass())) {
- throwSetIllegalArgumentException(value);
- }
- }
- unsafe.putObject(base, fieldOffset, value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/UnsafeStaticShortFieldAccessorImpl.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2001, 2005, 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.
- */
-
-package sun.reflect;
-
-import java.lang.reflect.Field;
-
-class UnsafeStaticShortFieldAccessorImpl extends UnsafeStaticFieldAccessorImpl {
- UnsafeStaticShortFieldAccessorImpl(Field field) {
- super(field);
- }
-
- public Object get(Object obj) throws IllegalArgumentException {
- return Short.valueOf(getShort(obj));
- }
-
- public boolean getBoolean(Object obj) throws IllegalArgumentException {
- throw newGetBooleanIllegalArgumentException();
- }
-
- public byte getByte(Object obj) throws IllegalArgumentException {
- throw newGetByteIllegalArgumentException();
- }
-
- public char getChar(Object obj) throws IllegalArgumentException {
- throw newGetCharIllegalArgumentException();
- }
-
- public short getShort(Object obj) throws IllegalArgumentException {
- return unsafe.getShort(base, fieldOffset);
- }
-
- public int getInt(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public long getLong(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public float getFloat(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public double getDouble(Object obj) throws IllegalArgumentException {
- return getShort(obj);
- }
-
- public void set(Object obj, Object value)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(value);
- }
- if (value == null) {
- throwSetIllegalArgumentException(value);
- }
- if (value instanceof Byte) {
- unsafe.putShort(base, fieldOffset, ((Byte) value).byteValue());
- return;
- }
- if (value instanceof Short) {
- unsafe.putShort(base, fieldOffset, ((Short) value).shortValue());
- return;
- }
- throwSetIllegalArgumentException(value);
- }
-
- public void setBoolean(Object obj, boolean z)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(z);
- }
-
- public void setByte(Object obj, byte b)
- throws IllegalArgumentException, IllegalAccessException
- {
- setShort(obj, b);
- }
-
- public void setChar(Object obj, char c)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(c);
- }
-
- public void setShort(Object obj, short s)
- throws IllegalArgumentException, IllegalAccessException
- {
- if (isFinal) {
- throwFinalFieldIllegalAccessException(s);
- }
- unsafe.putShort(base, fieldOffset, s);
- }
-
- public void setInt(Object obj, int i)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(i);
- }
-
- public void setLong(Object obj, long l)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(l);
- }
-
- public void setFloat(Object obj, float f)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(f);
- }
-
- public void setDouble(Object obj, double d)
- throws IllegalArgumentException, IllegalAccessException
- {
- throwSetIllegalArgumentException(d);
- }
-}
--- a/jdk/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java Fri Apr 15 16:19:15 2016 +0100
@@ -32,7 +32,7 @@
import java.lang.reflect.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import sun.reflect.ConstantPool;
+import jdk.internal.reflect.ConstantPool;
import sun.reflect.generics.parser.SignatureParser;
import sun.reflect.generics.tree.TypeSignature;
--- a/jdk/src/java.base/share/classes/sun/reflect/annotation/AnnotationSupport.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/sun/reflect/annotation/AnnotationSupport.java Fri Apr 15 16:19:15 2016 +0100
@@ -37,7 +37,7 @@
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.JavaLangAccess;
-import sun.reflect.ReflectionFactory;
+import jdk.internal.reflect.ReflectionFactory;
public final class AnnotationSupport {
private static final JavaLangAccess LANG_ACCESS = SharedSecrets.getJavaLangAccess();
--- a/jdk/src/java.base/share/classes/sun/reflect/annotation/TypeAnnotationParser.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/sun/reflect/annotation/TypeAnnotationParser.java Fri Apr 15 16:19:15 2016 +0100
@@ -36,7 +36,7 @@
import java.util.Map;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.misc.JavaLangAccess;
-import sun.reflect.ConstantPool;
+import jdk.internal.reflect.ConstantPool;
import static sun.reflect.annotation.TypeAnnotation.*;
/**
--- a/jdk/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java Fri Apr 15 16:19:15 2016 +0100
@@ -30,7 +30,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.Reflection;
import sun.security.util.SecurityConstants;
public final class ReflectUtil {
--- a/jdk/src/java.base/share/native/libjava/Class.c Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/native/libjava/Class.c Fri Apr 15 16:19:15 2016 +0100
@@ -43,7 +43,7 @@
#define OBJ "Ljava/lang/Object;"
#define CLS "Ljava/lang/Class;"
-#define CPL "Lsun/reflect/ConstantPool;"
+#define CPL "Ljdk/internal/reflect/ConstantPool;"
#define STR "Ljava/lang/String;"
#define FLD "Ljava/lang/reflect/Field;"
#define MHD "Ljava/lang/reflect/Method;"
--- a/jdk/src/java.base/share/native/libjava/ConstantPool.c Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/native/libjava/ConstantPool.c Fri Apr 15 16:19:15 2016 +0100
@@ -24,111 +24,111 @@
*/
#include "jvm.h"
-#include "sun_reflect_ConstantPool.h"
+#include "jdk_internal_reflect_ConstantPool.h"
-JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getSize0
+JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getSize0
(JNIEnv *env, jobject unused, jobject jcpool)
{
return JVM_ConstantPoolGetSize(env, unused, jcpool);
}
-JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAt0
+JNIEXPORT jclass JNICALL Java_jdk_internal_reflect_ConstantPool_getClassAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetClassAt(env, unused, jcpool, index);
}
-JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAtIfLoaded0
+JNIEXPORT jclass JNICALL Java_jdk_internal_reflect_ConstantPool_getClassAtIfLoaded0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetClassAtIfLoaded(env, unused, jcpool, index);
}
-JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getClassRefIndexAt0
+JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getClassRefIndexAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetClassRefIndexAt(env, unused, jcpool, index);
}
-JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAt0
+JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getMethodAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetMethodAt(env, unused, jcpool, index);
}
-JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0
+JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getMethodAtIfLoaded0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetMethodAtIfLoaded(env, unused, jcpool, index);
}
-JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAt0
+JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getFieldAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetFieldAt(env, unused, jcpool, index);
}
-JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0
+JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getFieldAtIfLoaded0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetFieldAtIfLoaded(env, unused, jcpool, index);
}
-JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0
+JNIEXPORT jobjectArray JNICALL Java_jdk_internal_reflect_ConstantPool_getMemberRefInfoAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetMemberRefInfoAt(env, unused, jcpool, index);
}
-JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getNameAndTypeRefIndexAt0
+JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefIndexAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetNameAndTypeRefIndexAt(env, unused, jcpool, index);
}
-JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getNameAndTypeRefInfoAt0
+JNIEXPORT jobjectArray JNICALL Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefInfoAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetNameAndTypeRefInfoAt(env, unused, jcpool, index);
}
-JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getIntAt0
+JNIEXPORT jint JNICALL Java_jdk_internal_reflect_ConstantPool_getIntAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetIntAt(env, unused, jcpool, index);
}
-JNIEXPORT jlong JNICALL Java_sun_reflect_ConstantPool_getLongAt0
+JNIEXPORT jlong JNICALL Java_jdk_internal_reflect_ConstantPool_getLongAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetLongAt(env, unused, jcpool, index);
}
-JNIEXPORT jfloat JNICALL Java_sun_reflect_ConstantPool_getFloatAt0
+JNIEXPORT jfloat JNICALL Java_jdk_internal_reflect_ConstantPool_getFloatAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetFloatAt(env, unused, jcpool, index);
}
-JNIEXPORT jdouble JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0
+JNIEXPORT jdouble JNICALL Java_jdk_internal_reflect_ConstantPool_getDoubleAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetDoubleAt(env, unused, jcpool, index);
}
-JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getStringAt0
+JNIEXPORT jstring JNICALL Java_jdk_internal_reflect_ConstantPool_getStringAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetStringAt(env, unused, jcpool, index);
}
-JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getUTF8At0
+JNIEXPORT jstring JNICALL Java_jdk_internal_reflect_ConstantPool_getUTF8At0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetUTF8At(env, unused, jcpool, index);
}
-JNIEXPORT jbyte JNICALL Java_sun_reflect_ConstantPool_getTagAt0
+JNIEXPORT jbyte JNICALL Java_jdk_internal_reflect_ConstantPool_getTagAt0
(JNIEnv *env, jobject unused, jobject jcpool, jint index)
{
return JVM_ConstantPoolGetTagAt(env, unused, jcpool, index);
--- a/jdk/src/java.base/share/native/libjava/NativeAccessors.c Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/native/libjava/NativeAccessors.c Fri Apr 15 16:19:15 2016 +0100
@@ -24,16 +24,16 @@
*/
#include "jvm.h"
-#include "sun_reflect_NativeConstructorAccessorImpl.h"
-#include "sun_reflect_NativeMethodAccessorImpl.h"
+#include "jdk_internal_reflect_NativeConstructorAccessorImpl.h"
+#include "jdk_internal_reflect_NativeMethodAccessorImpl.h"
-JNIEXPORT jobject JNICALL Java_sun_reflect_NativeMethodAccessorImpl_invoke0
+JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_NativeMethodAccessorImpl_invoke0
(JNIEnv *env, jclass unused, jobject m, jobject obj, jobjectArray args)
{
return JVM_InvokeMethod(env, m, obj, args);
}
-JNIEXPORT jobject JNICALL Java_sun_reflect_NativeConstructorAccessorImpl_newInstance0
+JNIEXPORT jobject JNICALL Java_jdk_internal_reflect_NativeConstructorAccessorImpl_newInstance0
(JNIEnv *env, jclass unused, jobject c, jobjectArray args)
{
return JVM_NewInstanceFromConstructor(env, c, args);
--- a/jdk/src/java.base/share/native/libjava/Reflection.c Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.base/share/native/libjava/Reflection.c Fri Apr 15 16:19:15 2016 +0100
@@ -25,22 +25,22 @@
#include "jni.h"
#include "jvm.h"
-#include "sun_reflect_Reflection.h"
+#include "jdk_internal_reflect_Reflection.h"
JNIEXPORT jclass JNICALL
-Java_sun_reflect_Reflection_getCallerClass__(JNIEnv *env, jclass unused)
+Java_jdk_internal_reflect_Reflection_getCallerClass__(JNIEnv *env, jclass unused)
{
return JVM_GetCallerClass(env, JVM_CALLER_DEPTH);
}
JNIEXPORT jclass JNICALL
-Java_sun_reflect_Reflection_getCallerClass__I(JNIEnv *env, jclass unused, jint depth)
+Java_jdk_internal_reflect_Reflection_getCallerClass__I(JNIEnv *env, jclass unused, jint depth)
{
return JVM_GetCallerClass(env, depth);
}
JNIEXPORT jint JNICALL
-Java_sun_reflect_Reflection_getClassAccessFlags(JNIEnv *env, jclass unused, jclass cls)
+Java_jdk_internal_reflect_Reflection_getClassAccessFlags(JNIEnv *env, jclass unused, jclass cls)
{
return JVM_GetClassAccessFlags(env, cls);
}
--- a/jdk/src/java.logging/share/classes/java/util/logging/Logger.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.logging/share/classes/java/util/logging/Logger.java Fri Apr 15 16:19:15 2016 +0100
@@ -38,8 +38,8 @@
import java.util.ResourceBundle;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
* A Logger object is used to log messages for a specific
--- a/jdk/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialJavaObject.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.sql.rowset/share/classes/javax/sql/rowset/serial/SerialJavaObject.java Fri Apr 15 16:19:15 2016 +0100
@@ -30,8 +30,8 @@
import java.util.Arrays;
import java.util.Vector;
import javax.sql.rowset.RowSetWarning;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import sun.reflect.misc.ReflectUtil;
/**
@@ -141,7 +141,7 @@
* Check if the caller is allowed to access the specified class's package.
* If access is denied, throw a SecurityException.
*/
- Class<?> caller = sun.reflect.Reflection.getCallerClass();
+ Class<?> caller = Reflection.getCallerClass();
if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(),
c.getClassLoader())) {
ReflectUtil.checkPackageAccess(c);
--- a/jdk/src/java.sql/share/classes/java/sql/DriverManager.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/java.sql/share/classes/java/sql/DriverManager.java Fri Apr 15 16:19:15 2016 +0100
@@ -36,8 +36,8 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Stream;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
/**
--- a/jdk/src/jdk.unsupported/share/classes/module-info.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/jdk.unsupported/share/classes/module-info.java Fri Apr 15 16:19:15 2016 +0100
@@ -25,6 +25,6 @@
module jdk.unsupported {
exports sun.misc;
- //exports sun.reflect;
+ exports sun.reflect;
}
--- a/jdk/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java Fri Apr 15 16:19:15 2016 +0100
@@ -27,8 +27,8 @@
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.misc.VM;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
import java.lang.reflect.Field;
import java.security.ProtectionDomain;
@@ -55,7 +55,7 @@
public final class Unsafe {
static {
- sun.reflect.Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
+ Reflection.registerMethodsToFilter(Unsafe.class, "getUnsafe");
}
private Unsafe() {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.unsupported/share/classes/sun/reflect/Reflection.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2001, 2016, 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.
+ */
+
+package sun.reflect;
+
+public class Reflection {
+
+ private Reflection() { }
+
+ /**
+ * @deprecated This method is an internal API and will be removed.
+ * Use {@link StackWalker} to walk the stack and obtain the caller class
+ * with {@link StackWalker.StackFrame#getDeclaringClass} instead.
+ */
+ @Deprecated(forRemoval=true)
+ public static Class<?> getCallerClass(int depth) {
+ if (depth < 0)
+ throw new InternalError("depth must be positive");
+
+ // increase depth to account for delegation to the internal impl
+ return jdk.internal.reflect.Reflection.getCallerClass(depth + 1);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2001, 2016, 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.
+ */
+
+package sun.reflect;
+
+import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.Permission;
+import java.security.PrivilegedAction;
+
+public class ReflectionFactory {
+
+ private static final ReflectionFactory soleInstance = new ReflectionFactory();
+ private final jdk.internal.reflect.ReflectionFactory delegate;
+
+ private ReflectionFactory() {
+ delegate = AccessController.doPrivileged(
+ new PrivilegedAction<jdk.internal.reflect.ReflectionFactory>() {
+ public jdk.internal.reflect.ReflectionFactory run() {
+ return jdk.internal.reflect.ReflectionFactory.getReflectionFactory();
+ }
+ });
+ }
+
+ private static final Permission REFLECTION_FACTORY_ACCESS_PERM
+ = new RuntimePermission("reflectionFactoryAccess");
+
+ /**
+ * Provides the caller with the capability to instantiate reflective
+ * objects.
+ *
+ * <p> First, if there is a security manager, its {@code checkPermission}
+ * method is called with a {@link java.lang.RuntimePermission} with target
+ * {@code "reflectionFactoryAccess"}. This may result in a securit
+ * exception.
+ *
+ * <p> The returned {@code ReflectionFactory} object should be carefully
+ * guarded by the caller, since it can be used to read and write private
+ * data and invoke private methods, as well as to load unverified bytecodes.
+ * It must never be passed to untrusted code.
+ *
+ * @throws SecurityException if a security manager exists and its
+ * {@code checkPermission} method doesn't allow access to
+ * the RuntimePermission "reflectionFactoryAccess".
+ */
+ public static ReflectionFactory getReflectionFactory() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(REFLECTION_FACTORY_ACCESS_PERM);
+ }
+ return soleInstance;
+ }
+
+ public Constructor<?> newConstructorForSerialization(Class<?> classToInstantiate,
+ Constructor<?> constructorToCall)
+ {
+ return delegate.newConstructorForSerialization(classToInstantiate,
+ constructorToCall);
+ }
+}
+
--- a/jdk/test/TEST.groups Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/TEST.groups Fri Apr 15 16:19:15 2016 +0100
@@ -76,6 +76,7 @@
sun/invoke \
sun/misc \
sun/reflect \
+ jdk/internal/reflect \
jdk/lambda \
jdk/internal/misc \
jdk/internal/ref \
@@ -495,8 +496,8 @@
sun/management/jmxremote/bootstrap/CustomLauncherTest.java \
sun/misc/JarIndex/metaInfFilenames/Basic.java \
sun/misc/JarIndex/JarIndexMergeForClassLoaderTest.java \
- sun/reflect/CallerSensitive/CallerSensitiveFinder.java \
- sun/reflect/CallerSensitive/MissingCallerSensitive.java \
+ jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java \
+ jdk/internal/reflect/CallerSensitive/MissingCallerSensitive.java \
sun/security/util/Resources/NewNamesFormat.java \
vm/verifier/defaultMethods/DefaultMethodRegressionTestsRun.java \
javax/xml/ws/clientjar/TestWsImport.java \
--- a/jdk/test/java/lang/StackWalker/DumpStackTest.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/java/lang/StackWalker/DumpStackTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -85,9 +85,9 @@
new CallFrame(DumpStackTest.class, "test"),
new CallFrame(DumpStackTest.class, "main"),
// if invoked from jtreg
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke0"), // non-public class
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke"),
- new CallFrame("sun.reflect.DelegatingMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke0"), // non-public class
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.DelegatingMethodAccessorImpl", "invoke"),
new CallFrame(Method.class, "invoke"),
new CallFrame(Thread.class, "run"),
};
@@ -141,9 +141,9 @@
new CallFrame(DumpStackTest.class, "testLambda"),
new CallFrame(DumpStackTest.class, "main"),
// if invoked from jtreg
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke0"),
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke"),
- new CallFrame("sun.reflect.DelegatingMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke0"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.DelegatingMethodAccessorImpl", "invoke"),
new CallFrame(Method.class, "invoke"),
new CallFrame(Thread.class, "run")
};
@@ -164,16 +164,16 @@
CallFrame[] callStack = new CallFrame[] {
new CallFrame(Thread.class, "getStackTrace"),
new CallFrame(DumpStackTest.class, "methodInvoke"),
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke0"),
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke"),
- new CallFrame("sun.reflect.DelegatingMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke0"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.DelegatingMethodAccessorImpl", "invoke"),
new CallFrame(Method.class, "invoke"),
new CallFrame(DumpStackTest.class, "testMethodInvoke"),
new CallFrame(DumpStackTest.class, "main"),
// if invoked from jtreg
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke0"),
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke"),
- new CallFrame("sun.reflect.DelegatingMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke0"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.DelegatingMethodAccessorImpl", "invoke"),
new CallFrame(Method.class, "invoke"),
new CallFrame(Thread.class, "run")
};
@@ -199,9 +199,9 @@
new CallFrame(DumpStackTest.class, "testMethodHandle"),
new CallFrame(DumpStackTest.class, "main"),
// if invoked from jtreg
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke0"),
- new CallFrame("sun.reflect.NativeMethodAccessorImpl", "invoke"),
- new CallFrame("sun.reflect.DelegatingMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke0"),
+ new CallFrame("jdk.internal.reflect.NativeMethodAccessorImpl", "invoke"),
+ new CallFrame("jdk.internal.reflect.DelegatingMethodAccessorImpl", "invoke"),
new CallFrame(Method.class, "invoke"),
new CallFrame(Thread.class, "run")
};
--- a/jdk/test/java/lang/StackWalker/EmbeddedStackWalkTest.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/java/lang/StackWalker/EmbeddedStackWalkTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -75,7 +75,7 @@
if (loops == 0) {
String caller = walker.walk(s ->
s.map(StackFrame::getClassName)
- .filter(cn -> !cn.startsWith("sun.reflect.") && !cn.startsWith("java.lang.invoke"))
+ .filter(cn -> !cn.startsWith("jdk.internal.reflect.") && !cn.startsWith("java.lang.invoke"))
.skip(2).findFirst()
).get();
assertEquals(caller, C1.class.getName());
@@ -122,7 +122,7 @@
static void call(StackWalker walker) {
String caller = walker.walk(s ->
s.map(StackFrame::getClassName)
- .filter(cn -> !cn.startsWith("sun.reflect.") && !cn.startsWith("java.lang.invoke"))
+ .filter(cn -> !cn.startsWith("jdk.internal.reflect.") && !cn.startsWith("java.lang.invoke"))
.skip(2).findFirst()
).get();
assertEquals(caller, C2.class.getName());
--- a/jdk/test/java/lang/StackWalker/HiddenFrames.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/java/lang/StackWalker/HiddenFrames.java Fri Apr 15 16:19:15 2016 +0100
@@ -98,7 +98,7 @@
void checkFrame(StackFrame frame) {
String cn = frame.getClassName();
- if (cn.startsWith("java.lang.reflect.") || cn.startsWith("sun.reflect.")) {
+ if (cn.startsWith("java.lang.reflect.") || cn.startsWith("jdk.internal.reflect.")) {
reflects.add(frame);
}
if (cn.contains("$$Lambda$")) {
--- a/jdk/test/java/lang/StackWalker/MultiThreadStackWalk.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/java/lang/StackWalker/MultiThreadStackWalk.java Fri Apr 15 16:19:15 2016 +0100
@@ -46,8 +46,8 @@
public class MultiThreadStackWalk {
static Set<String> infrastructureClasses = new TreeSet<>(Arrays.asList(
- "sun.reflect.NativeMethodAccessorImpl",
- "sun.reflect.DelegatingMethodAccessorImpl",
+ "jdk.internal.reflect.NativeMethodAccessorImpl",
+ "jdk.internal.reflect.DelegatingMethodAccessorImpl",
"java.lang.reflect.Method",
"com.sun.javatest.regtest.MainWrapper$MainThread",
"java.lang.Thread"
--- a/jdk/test/java/lang/StackWalker/StackWalkTest.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/java/lang/StackWalker/StackWalkTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -59,8 +59,8 @@
private static final int MAX_RANDOM_DEPTH = 1000;
static final Set<String> infrastructureClasses = new TreeSet<>(Arrays.asList(
- "sun.reflect.NativeMethodAccessorImpl",
- "sun.reflect.DelegatingMethodAccessorImpl",
+ "jdk.internal.reflect.NativeMethodAccessorImpl",
+ "jdk.internal.reflect.DelegatingMethodAccessorImpl",
"java.lang.reflect.Method",
"com.sun.javatest.regtest.MainWrapper$MainThread",
"com.sun.javatest.regtest.agent.MainWrapper$MainThread",
--- a/jdk/test/java/lang/StackWalker/VerifyStackTrace.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/java/lang/StackWalker/VerifyStackTrace.java Fri Apr 15 16:19:15 2016 +0100
@@ -101,9 +101,9 @@
"2: VerifyStackTrace$Handle.execute(VerifyStackTrace.java:147)\n" +
"3: VerifyStackTrace$Handle.run(VerifyStackTrace.java:160)\n" +
"4: VerifyStackTrace.invoke(VerifyStackTrace.java:190)\n" +
- "5: sun.reflect.NativeMethodAccessorImpl.invoke0(java.base/Native Method)\n" +
- "6: sun.reflect.NativeMethodAccessorImpl.invoke(java.base/NativeMethodAccessorImpl.java:62)\n" +
- "7: sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base/DelegatingMethodAccessorImpl.java:43)\n" +
+ "5: jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base/Native Method)\n" +
+ "6: jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base/NativeMethodAccessorImpl.java:62)\n" +
+ "7: jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base/DelegatingMethodAccessorImpl.java:43)\n" +
"8: java.lang.reflect.Method.invoke(java.base/Method.java:520)\n" +
"9: VerifyStackTrace$1.run(VerifyStackTrace.java:220)\n" +
"10: java.security.AccessController.doPrivileged(java.base/Native Method)\n" +
@@ -138,9 +138,9 @@
"5: java.lang.invoke.LambdaForm$MH/1395089624.invoke_MT(java.base/LambdaForm$MH)\n" +
"6: VerifyStackTrace$Handle.run(VerifyStackTrace.java:162)\n" +
"7: VerifyStackTrace.invoke(VerifyStackTrace.java:192)\n" +
- "8: sun.reflect.NativeMethodAccessorImpl.invoke0(java.base/Native Method)\n" +
- "9: sun.reflect.NativeMethodAccessorImpl.invoke(java.base/NativeMethodAccessorImpl.java:62)\n" +
- "10: sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base/DelegatingMethodAccessorImpl.java:43)\n" +
+ "8: jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base/Native Method)\n" +
+ "9: jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base/NativeMethodAccessorImpl.java:62)\n" +
+ "10: jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base/DelegatingMethodAccessorImpl.java:43)\n" +
"11: java.lang.reflect.Method.invoke(java.base/Method.java:520)\n" +
"12: VerifyStackTrace$1.run(VerifyStackTrace.java:222)\n" +
"13: java.security.AccessController.doPrivileged(java.base/Native Method)\n" +
--- a/jdk/test/java/lang/invoke/RevealDirectTest.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/java/lang/invoke/RevealDirectTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -24,7 +24,7 @@
/*
* @test
* @summary verify Lookup.revealDirect on a variety of input handles
- * @modules java.base/sun.reflect
+ * @modules java.base/jdk.internal.reflect
* @compile -XDignore.symbol.file RevealDirectTest.java
* @run junit/othervm -ea -esa test.java.lang.invoke.RevealDirectTest
*
@@ -311,7 +311,7 @@
if (!(mem instanceof AnnotatedElement)) return false;
AnnotatedElement ae = (AnnotatedElement) mem;
if (CS_CLASS != null)
- return ae.isAnnotationPresent(sun.reflect.CallerSensitive.class);
+ return ae.isAnnotationPresent(jdk.internal.reflect.CallerSensitive.class);
for (java.lang.annotation.Annotation a : ae.getDeclaredAnnotations()) {
if (a.toString().contains(".CallerSensitive"))
return true;
@@ -322,7 +322,7 @@
static {
Class<?> c = null;
try {
- c = sun.reflect.CallerSensitive.class;
+ c = jdk.internal.reflect.CallerSensitive.class;
} catch (SecurityException | LinkageError ex) {
}
CS_CLASS = c;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/AnonymousNewInstance/ManyNewInstanceAnonTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 7194897
+ * @summary JSR 292: Cannot create more than 16 instances of an anonymous class
+ * @modules java.base/jdk.internal.misc
+ * java.management
+ * @library /lib/testlibrary
+ * @author Robert Field
+ * @compile -XDignore.symbol.file ManyNewInstanceAnonTest.java
+ * @build jdk.testlibrary.*
+ * @run main ClassFileInstaller ManyNewInstanceAnonTest
+ * @run main/othervm -Xbootclasspath/a:. -Xverify:all ManyNewInstanceAnonTest
+ * @run main/othervm -Xbootclasspath/a:. -Xverify:all -Dsun.reflection.noInflation=true ManyNewInstanceAnonTest
+ */
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import jdk.internal.misc.Unsafe;
+
+public class ManyNewInstanceAnonTest {
+
+ static final int REPS = 20;
+ static final Class<?> klass = ManyNewInstanceAnonTest.class;
+
+ public static void main(String[] args) throws Exception {
+ Class<?> c = Unsafe.getUnsafe().defineAnonymousClass(klass, readClassFile(), null);
+ for (int i = 0; i < REPS; ++i) {
+ System.out.printf("%d: %s\n", i, c.newInstance());
+ }
+ System.out.println("Passed.");
+ }
+
+ private static byte[] readClassFile() throws Exception {
+ try (InputStream in = klass.getResourceAsStream(klass.getSimpleName() + ".class");
+ ByteArrayOutputStream out = new ByteArrayOutputStream())
+ {
+ int b;
+ while ((b = in.read()) != -1) {
+ out.write(b);
+ }
+ return out.toByteArray();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/CallerSensitive/CallerSensitiveFinder.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,234 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+
+import com.sun.tools.classfile.*;
+import com.sun.tools.jdeps.ClassFileReader;
+import static com.sun.tools.classfile.ConstantPool.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.stream.Stream;
+
+/*
+ * @test
+ * @bug 8010117
+ * @summary Verify if CallerSensitive methods are annotated with
+ * CallerSensitive annotation
+ * @modules jdk.jdeps/com.sun.tools.classfile jdk.jdeps/com.sun.tools.jdeps
+ * @build CallerSensitiveFinder
+ * @run main/othervm/timeout=900 CallerSensitiveFinder
+ */
+public class CallerSensitiveFinder {
+ private static int numThreads = 3;
+ private static boolean verbose = false;
+ private final ExecutorService pool;
+
+ public static void main(String[] args) throws Exception {
+ Stream<Path> classes = null;
+ String testclasses = System.getProperty("test.classes", ".");
+ int i = 0;
+ while (i < args.length) {
+ String arg = args[i++];
+ if (arg.equals("-v")) {
+ verbose = true;
+ } else {
+ Path p = Paths.get(testclasses, arg);
+ if (!p.toFile().exists()) {
+ throw new IllegalArgumentException(arg + " does not exist");
+ }
+ classes = Stream.of(p);
+ }
+ }
+
+ if (classes == null) {
+ classes = getPlatformClasses();
+ }
+
+ CallerSensitiveFinder csfinder = new CallerSensitiveFinder();
+ List<String> errors = csfinder.run(classes);
+
+ if (!errors.isEmpty()) {
+ throw new RuntimeException(errors.size() +
+ " caller-sensitive methods are missing @CallerSensitive annotation");
+ }
+ }
+
+ private final List<String> csMethodsMissingAnnotation =
+ Collections.synchronizedList(new ArrayList<>());
+ private final ReferenceFinder finder;
+ public CallerSensitiveFinder() {
+ this.finder = new ReferenceFinder(getFilter(), getVisitor());
+ pool = Executors.newFixedThreadPool(numThreads);
+
+ }
+
+ private ReferenceFinder.Filter getFilter() {
+ final String classname = "jdk/internal/reflect/Reflection";
+ final String method = "getCallerClass";
+ return new ReferenceFinder.Filter() {
+ public boolean accept(ConstantPool cpool, CPRefInfo cpref) {
+ try {
+ CONSTANT_NameAndType_info nat = cpref.getNameAndTypeInfo();
+ return cpref.getClassName().equals(classname) && nat.getName().equals(method);
+ } catch (ConstantPoolException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ };
+ }
+
+ private ReferenceFinder.Visitor getVisitor() {
+ return new ReferenceFinder.Visitor() {
+ public void visit(ClassFile cf, Method m, List<CPRefInfo> refs) {
+ try {
+ // ignore jdk.unsupported/sun.reflect.Reflection.getCallerClass
+ // which is a "special" delegate to the internal getCallerClass
+ if (cf.getName().equals("sun/reflect/Reflection") &&
+ m.getName(cf.constant_pool).equals("getCallerClass"))
+ return;
+
+ String name = String.format("%s#%s %s", cf.getName(),
+ m.getName(cf.constant_pool),
+ m.descriptor.getValue(cf.constant_pool));
+ if (!CallerSensitiveFinder.isCallerSensitive(m, cf.constant_pool)) {
+ csMethodsMissingAnnotation.add(name);
+ System.err.println("Missing @CallerSensitive: " + name);
+ } else {
+ if (verbose) {
+ System.out.format("@CS %s%n", name);
+ }
+ }
+ } catch (ConstantPoolException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ };
+ }
+
+ public List<String> run(Stream<Path> classes)throws IOException, InterruptedException,
+ ExecutionException, ConstantPoolException
+ {
+ classes.forEach(this::processPath);
+ waitForCompletion();
+ pool.shutdown();
+ return csMethodsMissingAnnotation;
+ }
+
+ void processPath(Path path) {
+ try {
+ ClassFileReader reader = ClassFileReader.newInstance(path);
+ for (ClassFile cf : reader.getClassFiles()) {
+ String classFileName = cf.getName();
+ // for each ClassFile
+ // parse constant pool to find matching method refs
+ // parse each method (caller)
+ // - visit and find method references matching the given method name
+ pool.submit(getTask(cf));
+ }
+ } catch (IOException x) {
+ throw new UncheckedIOException(x);
+ } catch (ConstantPoolException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ private static final String CALLER_SENSITIVE_ANNOTATION = "Ljdk/internal/reflect/CallerSensitive;";
+ private static boolean isCallerSensitive(Method m, ConstantPool cp)
+ throws ConstantPoolException
+ {
+ RuntimeAnnotations_attribute attr =
+ (RuntimeAnnotations_attribute)m.attributes.get(Attribute.RuntimeVisibleAnnotations);
+ int index = 0;
+ if (attr != null) {
+ for (int i = 0; i < attr.annotations.length; i++) {
+ Annotation ann = attr.annotations[i];
+ String annType = cp.getUTF8Value(ann.type_index);
+ if (CALLER_SENSITIVE_ANNOTATION.equals(annType)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private final List<FutureTask<Void>> tasks = new ArrayList<FutureTask<Void>>();
+ private FutureTask<Void> getTask(final ClassFile cf) {
+ FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() {
+ public Void call() throws Exception {
+ finder.parse(cf);
+ return null;
+ }
+ });
+ tasks.add(task);
+ return task;
+ }
+
+ private void waitForCompletion() throws InterruptedException, ExecutionException {
+ for (FutureTask<Void> t : tasks) {
+ t.get();
+ }
+ if (tasks.isEmpty()) {
+ throw new RuntimeException("No classes found, or specified.");
+ }
+ System.out.println("Parsed " + tasks.size() + " classfiles");
+ }
+
+ static Stream<Path> getPlatformClasses() throws IOException {
+ Path home = Paths.get(System.getProperty("java.home"));
+
+ // Either an exploded build or an image.
+ File classes = home.resolve("modules").toFile();
+ if (classes.isDirectory()) {
+ return Stream.of(classes.toPath());
+ } else {
+ return jrtPaths();
+ }
+ }
+
+ static Stream<Path> jrtPaths() {
+ FileSystem jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
+ Path root = jrt.getPath("/");
+
+ try {
+ return Files.walk(root)
+ .filter(p -> p.getNameCount() > 1)
+ .filter(p -> p.toString().endsWith(".class"));
+ } catch (IOException x) {
+ throw new UncheckedIOException(x);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/CallerSensitive/MissingCallerSensitive.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+
+
+/*
+ * @test
+ * @bug 8010117
+ * @summary Test CallerSensitiveFinder to find missing annotation
+ * @modules java.base/jdk.internal.reflect
+ * jdk.jdeps/com.sun.tools.classfile
+ * jdk.jdeps/com.sun.tools.jdeps
+ * @compile -XDignore.symbol.file MissingCallerSensitive.java
+ * @build CallerSensitiveFinder
+ * @run main MissingCallerSensitive
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
+import java.util.stream.Stream;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
+
+public class MissingCallerSensitive {
+ public static void main(String[] args) throws Exception {
+ String testclasses = System.getProperty("test.classes", ".");
+
+ Stream<Path> classes = Stream.of(Paths.get(testclasses, "MissingCallerSensitive.class"));
+
+ CallerSensitiveFinder csfinder = new CallerSensitiveFinder();
+ List<String> errors = csfinder.run(classes);
+ if (errors.size() != 1) {
+ throw new RuntimeException("Unexpected number of methods found: " + errors.size());
+ }
+ String m = errors.get(0);
+ if (!m.startsWith("MissingCallerSensitive#missingCallerSensitiveAnnotation")) {
+ throw new RuntimeException("Unexpected method missing annotation: " + m);
+ }
+ }
+
+ @CallerSensitive
+ public ClassLoader getCallerLoader() {
+ Class<?> c = Reflection.getCallerClass();
+ return c.getClassLoader();
+ }
+
+ public ClassLoader missingCallerSensitiveAnnotation() {
+ Class<?> c = Reflection.getCallerClass();
+ return c.getClassLoader();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/Reflection/GetCallerClass.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+
+package boot;
+
+public class GetCallerClass {
+ @jdk.internal.reflect.CallerSensitive
+ public ClassLoader getCallerLoader() {
+ Class<?> c = jdk.internal.reflect.Reflection.getCallerClass();
+ return c.getClassLoader();
+ }
+
+ public ClassLoader missingCallerSensitiveAnnotation() {
+ Class<?> c = jdk.internal.reflect.Reflection.getCallerClass();
+ return c.getClassLoader();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/Reflection/GetCallerClassTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+
+import boot.GetCallerClass;
+import java.lang.reflect.*;
+import jdk.internal.reflect.CallerSensitive;
+import jdk.internal.reflect.Reflection;
+
+public class GetCallerClassTest {
+ private final GetCallerClass gcc; // boot.GetCallerClass is in bootclasspath
+ GetCallerClassTest() {
+ this.gcc = new GetCallerClass();
+ }
+
+ public static void main(String[] args) throws Exception {
+ GetCallerClassTest gcct = new GetCallerClassTest();
+ // ensure methods are annotated with @CallerSensitive
+ ensureAnnotationPresent(boot.GetCallerClass.class, "getCallerLoader", true);
+ ensureAnnotationPresent(GetCallerClassTest.class, "testNonSystemMethod", false);
+ // call Reflection.getCallerClass from bootclasspath with and without @CS
+ gcct.testCallerSensitiveMethods();
+ // call Reflection.getCallerClass from classpath with @CS
+ gcct.testNonSystemMethod();
+ }
+
+ private static void ensureAnnotationPresent(Class<?> c, String name, boolean cs)
+ throws NoSuchMethodException
+ {
+ Method m = c.getDeclaredMethod(name);
+ if (!m.isAnnotationPresent(CallerSensitive.class)) {
+ throw new RuntimeException("@CallerSensitive not present in method " + m);
+ }
+ if (Reflection.isCallerSensitive(m) != cs) {
+ throw new RuntimeException("Unexpected: isCallerSensitive returns " +
+ Reflection.isCallerSensitive(m));
+ }
+ }
+
+ private void testCallerSensitiveMethods() {
+ try {
+ ClassLoader cl = gcc.getCallerLoader();
+ if (cl != GetCallerClassTest.class.getClassLoader()) {
+ throw new RuntimeException("mismatched class loader");
+ }
+ gcc.missingCallerSensitiveAnnotation();
+ throw new RuntimeException("getCallerLoader not marked with @CallerSensitive");
+ } catch (InternalError e) {
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ checkStackTrace(stackTrace, e);
+ if (!stackTrace[1].getClassName().equals(GetCallerClass.class.getName()) ||
+ !stackTrace[1].getMethodName().equals("missingCallerSensitiveAnnotation")) {
+ throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
+ }
+ if (!stackTrace[2].getClassName().equals(GetCallerClassTest.class.getName()) ||
+ !stackTrace[2].getMethodName().equals("testCallerSensitiveMethods")) {
+ throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
+ }
+ System.out.println("Expected error: " + e.getMessage());
+ }
+ }
+
+ @CallerSensitive
+ private void testNonSystemMethod() {
+ try {
+ Class<?> c = Reflection.getCallerClass();
+ throw new RuntimeException("@CallerSensitive testNonSystemMethods not supported");
+ } catch (InternalError e) {
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ checkStackTrace(stackTrace, e);
+ if (!stackTrace[1].getClassName().equals(GetCallerClassTest.class.getName()) ||
+ !stackTrace[1].getMethodName().equals("testNonSystemMethod")) {
+ throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
+ }
+ if (!stackTrace[2].getClassName().equals(GetCallerClassTest.class.getName()) ||
+ !stackTrace[2].getMethodName().equals("main")) {
+ throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
+ }
+ System.out.println("Expected error: " + e.getMessage());
+ }
+ }
+
+ private void checkStackTrace(StackTraceElement[] stackTrace, Error e) {
+ if (stackTrace.length < 3) {
+ throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
+ }
+
+ if (!stackTrace[0].getClassName().equals("jdk.internal.reflect.Reflection") ||
+ !stackTrace[0].getMethodName().equals("getCallerClass")) {
+ throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
+ }
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/Reflection/GetCallerClassTest.sh Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,70 @@
+#
+# 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.
+#
+# 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.
+#
+
+# @test
+# @bug 8010117
+# @summary Test if the VM enforces Reflection.getCallerClass
+# be called by methods annotated with CallerSensitive
+#
+# @run shell GetCallerClassTest.sh
+
+if [ "${TESTSRC}" = "" ]
+then
+ echo "TESTSRC not set. Test cannot execute. Failed."
+ exit 1
+fi
+echo "TESTSRC=${TESTSRC}"
+if [ "${TESTJAVA}" = "" ]
+then
+ echo "TESTJAVA not set. Test cannot execute. Failed."
+ exit 1
+fi
+echo "TESTJAVA=${TESTJAVA}"
+if [ "${COMPILEJAVA}" = "" ]
+then
+ COMPILEJAVA="${TESTJAVA}"
+fi
+echo "COMPILEJAVA=${COMPILEJAVA}"
+if [ "${TESTCLASSES}" = "" ]
+then
+ echo "TESTCLASSES not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+BCP=${TESTCLASSES}/bcp
+rm -rf ${BCP}
+mkdir ${BCP}
+
+EXTRAOPTS="-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED"
+
+# Compile GetCallerClass in bootclasspath
+${COMPILEJAVA}/bin/javac ${TESTTOOLVMOPTS} ${EXTRAOPTS} \
+ -XDignore.symbol.file \
+ -d ${BCP} ${TESTSRC}/GetCallerClass.java || exit 1
+
+${COMPILEJAVA}/bin/javac ${TESTTOOLVMOPTS} ${EXTRAOPTS} \
+ -XDignore.symbol.file -cp ${BCP} \
+ -d ${TESTCLASSES} ${TESTSRC}/GetCallerClassTest.java || exit 2
+
+${TESTJAVA}/bin/java ${TESTVMOPTS} ${EXTRAOPTS} -Xbootclasspath/a:${BCP} \
+ -cp ${TESTCLASSES} GetCallerClassTest || exit 3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/Reflection/GetCallerClassWithDepth.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8025799
+ * @summary Reflection.getCallerClass(int)
+ * @modules java.base/jdk.internal.reflect
+ * @run main GetCallerClassWithDepth
+ */
+
+import jdk.internal.reflect.Reflection;
+
+public class GetCallerClassWithDepth {
+ public static void main(String[] args) throws Exception {
+ Class<?> c = Test.test();
+ assertEquals(c, GetCallerClassWithDepth.class);
+ Class<?> caller = Test.caller();
+ assertEquals(caller, GetCallerClassWithDepth.class);
+ Test.selfTest();
+
+ try {
+ Reflection.getCallerClass(-1);
+ throw new RuntimeException("getCallerClass(-1) should fail");
+ } catch (Error e) {
+ System.out.println("Expected: " + e.getMessage());
+ }
+ }
+
+ public Class<?> getCallerClass() {
+ // 0: Reflection 1: getCallerClass 2: Test.test 3: main
+ return Reflection.getCallerClass(3);
+ }
+
+ static void assertEquals(Class<?> c, Class<?> expected) {
+ if (c != expected) {
+ throw new RuntimeException("Incorrect caller: " + c);
+ }
+ }
+
+ static class Test {
+ // Returns the caller of this method
+ public static Class<?> test() {
+ return new GetCallerClassWithDepth().getCallerClass();
+ }
+
+ // Returns the caller of this method
+ public static Class<?> caller() {
+ // 0: Reflection 1: Test.caller 2: main
+ return Reflection.getCallerClass(2);
+ }
+ public static void selfTest() {
+ // 0: Reflection 1: Test.selfTest
+ Class<?> c = Reflection.getCallerClass(1);
+ assertEquals(c, Test.class);
+ Inner1.deep();
+ }
+
+ static class Inner1 {
+ static void deep() {
+ deeper();
+ }
+ static void deeper() {
+ Inner2.deepest();
+ }
+ static class Inner2 {
+ static void deepest() {
+ // 0: Reflection 1: deepest 2: deeper 3: deep 4: Test.selfTest
+ Class<?> c = Reflection.getCallerClass(4);
+ assertEquals(c, Test.class);
+ }
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/constantPool/ConstantPoolTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8141615
+ * @summary Tests new public methods at ConstantPool
+ * @modules java.base/jdk.internal.misc
+ * java.base/jdk.internal.reflect
+ * @library /lib/testlibrary
+ * @compile ConstantPoolTestDummy.jasm
+ * @run main jdk.internal.reflect.constantPool.ConstantPoolTest
+ */
+
+package jdk.internal.reflect.constantPool;
+
+import java.util.HashMap;
+import java.util.Map;
+import jdk.internal.misc.SharedSecrets;
+import jdk.testlibrary.Asserts;
+import jdk.internal.reflect.ConstantPool;
+
+public class ConstantPoolTest {
+
+ private static final Class<?> TEST_CLASS = ConstantPoolTestDummy.class;
+ private static final ConstantPool CP = SharedSecrets.getJavaLangAccess()
+ .getConstantPool(TEST_CLASS);
+
+ public static void main(String[] s) {
+ for (TestCase testCase : TestCase.values()) {
+ testCase.test();
+ }
+ }
+
+ public static enum TestCase {
+ GET_TAG_AT {
+ {
+ referenceMap.put(1, ConstantPool.Tag.METHODREF);
+ referenceMap.put(2, ConstantPool.Tag.CLASS);
+ referenceMap.put(4, ConstantPool.Tag.UTF8);
+ referenceMap.put(10, ConstantPool.Tag.NAMEANDTYPE);
+ referenceMap.put(13, ConstantPool.Tag.LONG);
+ referenceMap.put(15, ConstantPool.Tag.INTEGER);
+ referenceMap.put(16, ConstantPool.Tag.INTERFACEMETHODREF);
+ referenceMap.put(21, ConstantPool.Tag.DOUBLE);
+ referenceMap.put(23, ConstantPool.Tag.STRING);
+ referenceMap.put(25, ConstantPool.Tag.INVOKEDYNAMIC);
+ referenceMap.put(29, ConstantPool.Tag.METHODHANDLE);
+ referenceMap.put(30, ConstantPool.Tag.METHODTYPE);
+ referenceMap.put(48, ConstantPool.Tag.FIELDREF);
+ referenceMap.put(52, ConstantPool.Tag.FLOAT);
+ }
+ @Override
+ void testIndex(int cpi, Object reference) {
+ ConstantPool.Tag tagToVerify = CP.getTagAt(cpi);
+ ConstantPool.Tag tagToRefer = (ConstantPool.Tag) reference;
+ String msg = String.format("Method getTagAt works not as expected"
+ + "at CP entry #%d: got CP tag %s, but should be %s",
+ cpi, tagToVerify.name(), tagToRefer.name());
+ Asserts.assertEquals(tagToVerify, tagToRefer, msg);
+ }
+ },
+ GET_CLASS_REF_INDEX_AT {
+ {
+ referenceMap.put(1, 3);
+ referenceMap.put(16, 17);
+ referenceMap.put(32, 35);
+ referenceMap.put(34, 3);
+ referenceMap.put(48, 2);
+ }
+ @Override
+ void testIndex(int cpi, Object reference) {
+ int indexToVerify = CP.getClassRefIndexAt(cpi);
+ int indexToRefer = (int) reference;
+ String msg = String.format("Method getClassRefIndexAt works not"
+ + " as expected at CP entry #%d:"
+ + " got index %d, but should be %d",
+ cpi, indexToVerify, indexToRefer);
+ Asserts.assertEquals(indexToVerify, indexToRefer, msg);
+ }
+ },
+ GET_NAME_AND_TYPE_REF_INDEX_AT {
+ {
+ referenceMap.put(1, 10);
+ referenceMap.put(16, 18);
+ referenceMap.put(25, 26);
+ referenceMap.put(32, 36);
+ referenceMap.put(34, 37);
+ referenceMap.put(48, 49);
+ }
+ @Override
+ void testIndex(int cpi, Object reference) {
+ int indexToRefer = (int) reference;
+ int indexToVerify = CP.getNameAndTypeRefIndexAt(cpi);
+ String msg = String.format("Method getNameAndTypeRefIndexAt works"
+ + " not as expected at CP entry #%d:"
+ + " got index %d, but should be %d",
+ cpi, indexToVerify, indexToRefer);
+ Asserts.assertEquals(indexToVerify, indexToRefer, msg);
+ }
+ },
+ GET_NAME_AND_TYPE_REF_INFO_AT {
+ {
+ referenceMap.put(10, new String[]{"<init>", "()V"});
+ referenceMap.put(18, new String[]{"run", "()V"});
+ referenceMap.put(26, new String[]{"accept", "()Ljava/util/function/Consumer;"});
+ referenceMap.put(36, new String[]{"metafactory",
+ "(Ljava/lang/invoke/MethodHandles$Lookup;"
+ + "Ljava/lang/String;Ljava/lang/invoke/MethodType;"
+ + "Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;"
+ + "Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"});
+ referenceMap.put(37, new String[]{"toString", "()Ljava/lang/String;"});
+ referenceMap.put(49, new String[]{"myField", "I"});
+ }
+ @Override
+ void testIndex(int cpi, Object reference) {
+ String[] natInfo = CP.getNameAndTypeRefInfoAt(cpi);
+ String msg = String.format("Method getNameAndTypeRefInfoAt"
+ + " works not as expected at CP entry #%d:"
+ + " returned value should not be null", cpi);
+ Asserts.assertNotNull(natInfo, msg);
+ String[] castedReference = (String[]) reference;
+ int natInfoLength = natInfo.length;
+ msg = String.format("Method getNameAndTypeRefInfoAt"
+ + " works not as expected at CP entry #%d:"
+ + " length of the returned string array is %d, but should be 2",
+ cpi, natInfoLength);
+ Asserts.assertEquals(natInfoLength, 2, msg);
+ String[] nameOrType = new String[]{"name", "type"};
+ for (int i = 0; i < 2; i++) {
+ String infoToVerify = natInfo[i];
+ String infoToRefer = castedReference[i];
+ msg = String.format("Method getNameAndTypeRefInfoAt"
+ + " works not as expected at CP entry #%d:"
+ + " got %s info %s, but should be %s",
+ cpi, nameOrType[i], infoToVerify, infoToRefer);
+ Asserts.assertEquals(infoToVerify, infoToRefer, msg);
+ }
+ }
+ };
+
+ protected final Map<Integer, Object> referenceMap;
+ TestCase() {
+ this.referenceMap = new HashMap<>();
+ }
+ abstract void testIndex(int cpi, Object reference);
+ public void test() {
+ referenceMap.forEach(this::testIndex);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/jdk/internal/reflect/constantPool/ConstantPoolTestDummy.jasm Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+package jdk/internal/reflect/constantPool;
+
+super public #2; //class ConstantPoolTestDummy
+ version 52:0
+{
+
+// Actually, only first 13 constant pool entries are actually used by the class
+// and its methods. All the rest are added just for the testing of getTagAt method
+// and getNameAndTypeRefIndexAt method.
+
+const #1 = Method #3.#10; // java/lang/Object."<init>":"()V"
+const #2 = class #11; // ConstantPoolTestDummy
+const #3 = class #12; // java/lang/Object
+const #4 = Asciz "<init>";
+const #5 = Asciz "()V";
+const #6 = Asciz "Code";
+const #7 = Asciz "LineNumberTable";
+const #8 = Asciz "SourceFile";
+const #9 = Asciz "ConstantPoolTestDummy.java";
+const #10 = NameAndType #4:#5; // "<init>":"()V"
+const #11 = Asciz "jdk/internal/reflect/constantPool/ConstantPoolTestDummy";
+const #12 = Asciz "java/lang/Object";
+const #13 = long 6l;
+const #15 = int 1;
+const #16 = InterfaceMethod #17.#18; // java/lang/Runnable.run:"()V"
+const #17 = class #19; // java/lang/Runnable
+const #18 = NameAndType #20:#5; // run:"()V"
+const #19 = Asciz "java/lang/Runnable";
+const #20 = Asciz "run";
+const #21 = double 1.45d;
+const #23 = String #24; // "Hello"
+const #24 = Asciz "Hello";
+const #25 = InvokeDynamic 0:#26; // REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;":accept:"()Ljava/util/function/Consumer;" MethodType "(Ljava/lang/Object;)V", MethodHandle REF_invokeVirtual:java/lang/Object.toString:"()Ljava/lang/String;", MethodType "(Ljava/lang/Object;)V"
+const #26 = NameAndType #27:#28; // accept:"()Ljava/util/function/Consumer;"
+const #27 = Asciz "accept";
+const #28 = Asciz "()Ljava/util/function/Consumer;";
+const #29 = MethodHandle 6:#32; // REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
+const #30 = MethodType #33; // "(Ljava/lang/Object;)V"
+const #31 = MethodHandle 5:#34; // REF_invokeVirtual:java/lang/Object.toString:"()Ljava/lang/String;"
+const #32 = Method #35.#36; // java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
+const #33 = Asciz "(Ljava/lang/Object;)V";
+const #34 = Method #3.#37; // java/lang/Object.toString:"()Ljava/lang/String;"
+const #35 = class #38; // java/lang/invoke/LambdaMetafactory
+const #36 = NameAndType #39:#40; // metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
+const #37 = NameAndType #41:#42; // toString:"()Ljava/lang/String;"
+const #38 = Asciz "java/lang/invoke/LambdaMetafactory";
+const #39 = Asciz "metafactory";
+const #40 = Asciz "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;";
+const #41 = Asciz "toString";
+const #42 = Asciz "()Ljava/lang/String;";
+const #43 = class #46; // java/lang/invoke/MethodHandles$Lookup
+const #44 = Asciz "Lookup";
+const #45 = class #47; // java/lang/invoke/MethodHandles
+const #46 = Asciz "java/lang/invoke/MethodHandles$Lookup";
+const #47 = Asciz "java/lang/invoke/MethodHandles";
+const #48 = Field #2.#49; // jdk/internal/reflect/constantPool/ConstantPoolTestDummy.myField:"I"
+const #49 = NameAndType #50:#51; // myField:"I"
+const #50 = Asciz "myField";
+const #51 = Asciz "I";
+const #52 = float 1.34f;
+
+public Method #4:#5 // "<init>":"()V"
+
+ stack 1 locals 1
+{
+3 0: aload_0;
+ 1: invokespecial #1; // Method java/lang/Object."<init>":"()V";
+ 4: return;
+}
+
+public static final InnerClass #44= #43 of #45; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
+
+BootstrapMethod #29 #30 #31 #30;
+
+} // end Class ConstantPoolTestDummy
--- a/jdk/test/sun/reflect/AnonymousNewInstance/ManyNewInstanceAnonTest.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2013, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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.
- */
-
-/*
- * @test
- * @bug 7194897
- * @summary JSR 292: Cannot create more than 16 instances of an anonymous class
- * @modules java.base/jdk.internal.misc
- * java.management
- * @library /lib/testlibrary
- * @author Robert Field
- * @compile -XDignore.symbol.file ManyNewInstanceAnonTest.java
- * @build jdk.testlibrary.*
- * @run main ClassFileInstaller ManyNewInstanceAnonTest
- * @run main/othervm -Xbootclasspath/a:. -Xverify:all ManyNewInstanceAnonTest
- * @run main/othervm -Xbootclasspath/a:. -Xverify:all -Dsun.reflection.noInflation=true ManyNewInstanceAnonTest
- */
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import jdk.internal.misc.Unsafe;
-
-public class ManyNewInstanceAnonTest {
-
- static final int REPS = 20;
- static final Class<?> klass = ManyNewInstanceAnonTest.class;
-
- public static void main(String[] args) throws Exception {
- Class<?> c = Unsafe.getUnsafe().defineAnonymousClass(klass, readClassFile(), null);
- for (int i = 0; i < REPS; ++i) {
- System.out.printf("%d: %s\n", i, c.newInstance());
- }
- System.out.println("Passed.");
- }
-
- private static byte[] readClassFile() throws Exception {
- try (InputStream in = klass.getResourceAsStream(klass.getSimpleName() + ".class");
- ByteArrayOutputStream out = new ByteArrayOutputStream())
- {
- int b;
- while ((b = in.read()) != -1) {
- out.write(b);
- }
- return out.toByteArray();
- }
- }
-}
--- a/jdk/test/sun/reflect/CallerSensitive/CallerSensitiveFinder.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,228 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-
-import com.sun.tools.classfile.*;
-import com.sun.tools.jdeps.ClassFileReader;
-import static com.sun.tools.classfile.ConstantPool.*;
-import java.io.File;
-import java.io.IOException;
-import java.io.UncheckedIOException;
-import java.net.URI;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-import java.util.stream.Stream;
-
-/*
- * @test
- * @bug 8010117
- * @summary Verify if CallerSensitive methods are annotated with
- * sun.reflect.CallerSensitive annotation
- * @modules jdk.jdeps/com.sun.tools.classfile jdk.jdeps/com.sun.tools.jdeps
- * @build CallerSensitiveFinder
- * @run main/othervm/timeout=900 CallerSensitiveFinder
- */
-public class CallerSensitiveFinder {
- private static int numThreads = 3;
- private static boolean verbose = false;
- private final ExecutorService pool;
-
- public static void main(String[] args) throws Exception {
- Stream<Path> classes = null;
- String testclasses = System.getProperty("test.classes", ".");
- int i = 0;
- while (i < args.length) {
- String arg = args[i++];
- if (arg.equals("-v")) {
- verbose = true;
- } else {
- Path p = Paths.get(testclasses, arg);
- if (!p.toFile().exists()) {
- throw new IllegalArgumentException(arg + " does not exist");
- }
- classes = Stream.of(p);
- }
- }
-
- if (classes == null) {
- classes = getPlatformClasses();
- }
-
- CallerSensitiveFinder csfinder = new CallerSensitiveFinder();
- List<String> errors = csfinder.run(classes);
-
- if (!errors.isEmpty()) {
- throw new RuntimeException(errors.size() +
- " caller-sensitive methods are missing @CallerSensitive annotation");
- }
- }
-
- private final List<String> csMethodsMissingAnnotation =
- Collections.synchronizedList(new ArrayList<>());
- private final ReferenceFinder finder;
- public CallerSensitiveFinder() {
- this.finder = new ReferenceFinder(getFilter(), getVisitor());
- pool = Executors.newFixedThreadPool(numThreads);
-
- }
-
- private ReferenceFinder.Filter getFilter() {
- final String classname = "sun/reflect/Reflection";
- final String method = "getCallerClass";
- return new ReferenceFinder.Filter() {
- public boolean accept(ConstantPool cpool, CPRefInfo cpref) {
- try {
- CONSTANT_NameAndType_info nat = cpref.getNameAndTypeInfo();
- return cpref.getClassName().equals(classname) && nat.getName().equals(method);
- } catch (ConstantPoolException ex) {
- throw new RuntimeException(ex);
- }
- }
- };
- }
-
- private ReferenceFinder.Visitor getVisitor() {
- return new ReferenceFinder.Visitor() {
- public void visit(ClassFile cf, Method m, List<CPRefInfo> refs) {
- try {
- String name = String.format("%s#%s %s", cf.getName(),
- m.getName(cf.constant_pool),
- m.descriptor.getValue(cf.constant_pool));
- if (!CallerSensitiveFinder.isCallerSensitive(m, cf.constant_pool)) {
- csMethodsMissingAnnotation.add(name);
- System.err.println("Missing @CallerSensitive: " + name);
- } else {
- if (verbose) {
- System.out.format("@CS %s%n", name);
- }
- }
- } catch (ConstantPoolException ex) {
- throw new RuntimeException(ex);
- }
- }
- };
- }
-
- public List<String> run(Stream<Path> classes)throws IOException, InterruptedException,
- ExecutionException, ConstantPoolException
- {
- classes.forEach(this::processPath);
- waitForCompletion();
- pool.shutdown();
- return csMethodsMissingAnnotation;
- }
-
- void processPath(Path path) {
- try {
- ClassFileReader reader = ClassFileReader.newInstance(path);
- for (ClassFile cf : reader.getClassFiles()) {
- String classFileName = cf.getName();
- // for each ClassFile
- // parse constant pool to find matching method refs
- // parse each method (caller)
- // - visit and find method references matching the given method name
- pool.submit(getTask(cf));
- }
- } catch (IOException x) {
- throw new UncheckedIOException(x);
- } catch (ConstantPoolException x) {
- throw new RuntimeException(x);
- }
- }
-
- private static final String CALLER_SENSITIVE_ANNOTATION = "Lsun/reflect/CallerSensitive;";
- private static boolean isCallerSensitive(Method m, ConstantPool cp)
- throws ConstantPoolException
- {
- RuntimeAnnotations_attribute attr =
- (RuntimeAnnotations_attribute)m.attributes.get(Attribute.RuntimeVisibleAnnotations);
- int index = 0;
- if (attr != null) {
- for (int i = 0; i < attr.annotations.length; i++) {
- Annotation ann = attr.annotations[i];
- String annType = cp.getUTF8Value(ann.type_index);
- if (CALLER_SENSITIVE_ANNOTATION.equals(annType)) {
- return true;
- }
- }
- }
- return false;
- }
-
- private final List<FutureTask<Void>> tasks = new ArrayList<FutureTask<Void>>();
- private FutureTask<Void> getTask(final ClassFile cf) {
- FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() {
- public Void call() throws Exception {
- finder.parse(cf);
- return null;
- }
- });
- tasks.add(task);
- return task;
- }
-
- private void waitForCompletion() throws InterruptedException, ExecutionException {
- for (FutureTask<Void> t : tasks) {
- t.get();
- }
- if (tasks.isEmpty()) {
- throw new RuntimeException("No classes found, or specified.");
- }
- System.out.println("Parsed " + tasks.size() + " classfiles");
- }
-
- static Stream<Path> getPlatformClasses() throws IOException {
- Path home = Paths.get(System.getProperty("java.home"));
-
- // Either an exploded build or an image.
- File classes = home.resolve("modules").toFile();
- if (classes.isDirectory()) {
- return Stream.of(classes.toPath());
- } else {
- return jrtPaths();
- }
- }
-
- static Stream<Path> jrtPaths() {
- FileSystem jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
- Path root = jrt.getPath("/");
-
- try {
- return Files.walk(root)
- .filter(p -> p.getNameCount() > 1)
- .filter(p -> p.toString().endsWith(".class"));
- } catch (IOException x) {
- throw new UncheckedIOException(x);
- }
- }
-}
--- a/jdk/test/sun/reflect/CallerSensitive/MissingCallerSensitive.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-
-
-/*
- * @test
- * @bug 8010117
- * @summary Test CallerSensitiveFinder to find missing annotation
- * @modules java.base/sun.reflect
- * jdk.jdeps/com.sun.tools.classfile
- * jdk.jdeps/com.sun.tools.jdeps
- * @compile -XDignore.symbol.file MissingCallerSensitive.java
- * @build CallerSensitiveFinder
- * @run main MissingCallerSensitive
- */
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.*;
-import java.util.stream.Stream;
-
-public class MissingCallerSensitive {
- public static void main(String[] args) throws Exception {
- String testclasses = System.getProperty("test.classes", ".");
-
- Stream<Path> classes = Stream.of(Paths.get(testclasses, "MissingCallerSensitive.class"));
-
- CallerSensitiveFinder csfinder = new CallerSensitiveFinder();
- List<String> errors = csfinder.run(classes);
- if (errors.size() != 1) {
- throw new RuntimeException("Unexpected number of methods found: " + errors.size());
- }
- String m = errors.get(0);
- if (!m.startsWith("MissingCallerSensitive#missingCallerSensitiveAnnotation")) {
- throw new RuntimeException("Unexpected method missing annotation: " + m);
- }
- }
-
- @sun.reflect.CallerSensitive
- public ClassLoader getCallerLoader() {
- Class<?> c = sun.reflect.Reflection.getCallerClass();
- return c.getClassLoader();
- }
-
- public ClassLoader missingCallerSensitiveAnnotation() {
- Class<?> c = sun.reflect.Reflection.getCallerClass();
- return c.getClassLoader();
- }
-}
--- a/jdk/test/sun/reflect/Reflection/GetCallerClass.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-
-package boot;
-
-public class GetCallerClass {
- @sun.reflect.CallerSensitive
- public ClassLoader getCallerLoader() {
- Class<?> c = sun.reflect.Reflection.getCallerClass();
- return c.getClassLoader();
- }
-
- public ClassLoader missingCallerSensitiveAnnotation() {
- Class<?> c = sun.reflect.Reflection.getCallerClass();
- return c.getClassLoader();
- }
-}
--- a/jdk/test/sun/reflect/Reflection/GetCallerClassTest.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
-/*
- * 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.
- *
- * 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.
- */
-
-import boot.GetCallerClass;
-import java.lang.reflect.*;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
-
-public class GetCallerClassTest {
- private final GetCallerClass gcc; // boot.GetCallerClass is in bootclasspath
- GetCallerClassTest() {
- this.gcc = new GetCallerClass();
- }
-
- public static void main(String[] args) throws Exception {
- GetCallerClassTest gcct = new GetCallerClassTest();
- // ensure methods are annotated with @CallerSensitive
- ensureAnnotationPresent(boot.GetCallerClass.class, "getCallerLoader", true);
- ensureAnnotationPresent(GetCallerClassTest.class, "testNonSystemMethod", false);
- // call Reflection.getCallerClass from bootclasspath with and without @CS
- gcct.testCallerSensitiveMethods();
- // call Reflection.getCallerClass from classpath with @CS
- gcct.testNonSystemMethod();
- }
-
- private static void ensureAnnotationPresent(Class<?> c, String name, boolean cs)
- throws NoSuchMethodException
- {
- Method m = c.getDeclaredMethod(name);
- if (!m.isAnnotationPresent(CallerSensitive.class)) {
- throw new RuntimeException("@CallerSensitive not present in method " + m);
- }
- if (Reflection.isCallerSensitive(m) != cs) {
- throw new RuntimeException("Unexpected: isCallerSensitive returns " +
- Reflection.isCallerSensitive(m));
- }
- }
-
- private void testCallerSensitiveMethods() {
- try {
- ClassLoader cl = gcc.getCallerLoader();
- if (cl != GetCallerClassTest.class.getClassLoader()) {
- throw new RuntimeException("mismatched class loader");
- }
- gcc.missingCallerSensitiveAnnotation();
- throw new RuntimeException("getCallerLoader not marked with @CallerSensitive");
- } catch (InternalError e) {
- StackTraceElement[] stackTrace = e.getStackTrace();
- checkStackTrace(stackTrace, e);
- if (!stackTrace[1].getClassName().equals(GetCallerClass.class.getName()) ||
- !stackTrace[1].getMethodName().equals("missingCallerSensitiveAnnotation")) {
- throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
- }
- if (!stackTrace[2].getClassName().equals(GetCallerClassTest.class.getName()) ||
- !stackTrace[2].getMethodName().equals("testCallerSensitiveMethods")) {
- throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
- }
- System.out.println("Expected error: " + e.getMessage());
- }
- }
-
- @CallerSensitive
- private void testNonSystemMethod() {
- try {
- Class<?> c = Reflection.getCallerClass();
- throw new RuntimeException("@CallerSensitive testNonSystemMethods not supported");
- } catch (InternalError e) {
- StackTraceElement[] stackTrace = e.getStackTrace();
- checkStackTrace(stackTrace, e);
- if (!stackTrace[1].getClassName().equals(GetCallerClassTest.class.getName()) ||
- !stackTrace[1].getMethodName().equals("testNonSystemMethod")) {
- throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
- }
- if (!stackTrace[2].getClassName().equals(GetCallerClassTest.class.getName()) ||
- !stackTrace[2].getMethodName().equals("main")) {
- throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
- }
- System.out.println("Expected error: " + e.getMessage());
- }
- }
-
- private void checkStackTrace(StackTraceElement[] stackTrace, Error e) {
- if (stackTrace.length < 3) {
- throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
- }
-
- if (!stackTrace[0].getClassName().equals("sun.reflect.Reflection") ||
- !stackTrace[0].getMethodName().equals("getCallerClass")) {
- throw new RuntimeException("Unexpected error: " + e.getMessage(), e);
- }
-
- }
-}
--- a/jdk/test/sun/reflect/Reflection/GetCallerClassTest.sh Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-#
-# 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.
-#
-# 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.
-#
-
-# @test
-# @bug 8010117
-# @summary Test if the VM enforces sun.reflect.Reflection.getCallerClass
-# be called by methods annotated with sun.reflect.CallerSensitive
-#
-# @run shell GetCallerClassTest.sh
-
-if [ "${TESTSRC}" = "" ]
-then
- echo "TESTSRC not set. Test cannot execute. Failed."
- exit 1
-fi
-echo "TESTSRC=${TESTSRC}"
-if [ "${TESTJAVA}" = "" ]
-then
- echo "TESTJAVA not set. Test cannot execute. Failed."
- exit 1
-fi
-echo "TESTJAVA=${TESTJAVA}"
-if [ "${COMPILEJAVA}" = "" ]
-then
- COMPILEJAVA="${TESTJAVA}"
-fi
-echo "COMPILEJAVA=${COMPILEJAVA}"
-if [ "${TESTCLASSES}" = "" ]
-then
- echo "TESTCLASSES not set. Test cannot execute. Failed."
- exit 1
-fi
-
-BCP=${TESTCLASSES}/bcp
-rm -rf ${BCP}
-mkdir ${BCP}
-
-EXTRAOPTS="-XaddExports:java.base/sun.reflect=ALL-UNNAMED"
-
-# Compile GetCallerClass in bootclasspath
-${COMPILEJAVA}/bin/javac ${TESTTOOLVMOPTS} ${EXTRAOPTS} \
- -XDignore.symbol.file \
- -d ${BCP} ${TESTSRC}/GetCallerClass.java || exit 1
-
-${COMPILEJAVA}/bin/javac ${TESTTOOLVMOPTS} ${EXTRAOPTS} \
- -XDignore.symbol.file -cp ${BCP} \
- -d ${TESTCLASSES} ${TESTSRC}/GetCallerClassTest.java || exit 2
-
-${TESTJAVA}/bin/java ${TESTVMOPTS} ${EXTRAOPTS} -Xbootclasspath/a:${BCP} \
- -cp ${TESTCLASSES} GetCallerClassTest || exit 3
--- a/jdk/test/sun/reflect/Reflection/GetCallerClassWithDepth.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/sun/reflect/Reflection/GetCallerClassWithDepth.java Fri Apr 15 16:19:15 2016 +0100
@@ -23,12 +23,13 @@
/*
* @test
- * @bug 8025799
- * @summary sun.reflect.Reflection.getCallerClass(int)
- * @modules java.base/sun.reflect
- * @run main GetCallerClassWithDepth
+ * @bug 8137058
+ * @summary Basic test for the unsupported Reflection.getCallerClass(int)
+ * @modules jdk.unsupported
*/
+import sun.reflect.Reflection;
+
public class GetCallerClassWithDepth {
public static void main(String[] args) throws Exception {
Class<?> c = Test.test();
@@ -38,7 +39,7 @@
Test.selfTest();
try {
- sun.reflect.Reflection.getCallerClass(-1);
+ Reflection.getCallerClass(-1);
throw new RuntimeException("getCallerClass(-1) should fail");
} catch (Error e) {
System.out.println("Expected: " + e.getMessage());
@@ -47,7 +48,7 @@
public Class<?> getCallerClass() {
// 0: Reflection 1: getCallerClass 2: Test.test 3: main
- return sun.reflect.Reflection.getCallerClass(3);
+ return Reflection.getCallerClass(3);
}
static void assertEquals(Class<?> c, Class<?> expected) {
@@ -65,11 +66,11 @@
// Returns the caller of this method
public static Class<?> caller() {
// 0: Reflection 1: Test.caller 2: main
- return sun.reflect.Reflection.getCallerClass(2);
+ return Reflection.getCallerClass(2);
}
public static void selfTest() {
// 0: Reflection 1: Test.selfTest
- Class<?> c = sun.reflect.Reflection.getCallerClass(1);
+ Class<?> c = Reflection.getCallerClass(1);
assertEquals(c, Test.class);
Inner1.deep();
}
@@ -84,7 +85,7 @@
static class Inner2 {
static void deepest() {
// 0: Reflection 1: deepest 2: deeper 3: deep 4: Test.selfTest
- Class<?> c = sun.reflect.Reflection.getCallerClass(4);
+ Class<?> c = Reflection.getCallerClass(4);
assertEquals(c, Test.class);
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/reflect/ReflectionFactory/NewConstructorForSerialization.java Fri Apr 15 16:19:15 2016 +0100
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016, 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.
+ *
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8137058
+ * @summary Basic test for the unsupported newConstructorForSerialization
+ * @modules jdk.unsupported
+ */
+
+import java.lang.reflect.Constructor;
+import sun.reflect.ReflectionFactory;
+
+public class NewConstructorForSerialization {
+
+ private static Constructor<?> getConstructor(Class<?> type)
+ throws NoSuchMethodException
+ {
+ ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
+ Constructor<?> objectConstructor = type.getConstructor((Class[]) null);
+
+ @SuppressWarnings("unchecked")
+ Constructor<?> c = (Constructor<?>) factory
+ .newConstructorForSerialization(type, objectConstructor);
+ return c;
+ }
+
+ public static void main(String[] args) throws Exception {
+ System.out.println(getConstructor(Object.class).newInstance());
+ System.out.println(getConstructor(Foo.class).newInstance());
+ System.out.println(getConstructor(Bar.class).newInstance());
+ }
+
+ static class Foo {
+ public Foo() { }
+ }
+
+ static class Bar extends Foo {
+ public Bar() { }
+ }
+}
--- a/jdk/test/sun/reflect/constantPool/ConstantPoolTest.java Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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.
- */
-
-/*
- * @test
- * @bug 8141615
- * @summary Tests new public methods at sun.reflect.ConstantPool
- * @modules java.base/jdk.internal.misc
- * java.base/sun.reflect
- * @library /lib/testlibrary
- * @compile ConstantPoolTestDummy.jasm
- * @run main sun.reflect.constantPool.ConstantPoolTest
- */
-
-package sun.reflect.constantPool;
-
-import java.util.HashMap;
-import java.util.Map;
-import jdk.internal.misc.SharedSecrets;
-import jdk.testlibrary.Asserts;
-import sun.reflect.ConstantPool;
-
-public class ConstantPoolTest {
-
- private static final Class<?> TEST_CLASS = ConstantPoolTestDummy.class;
- private static final ConstantPool CP = SharedSecrets.getJavaLangAccess()
- .getConstantPool(TEST_CLASS);
-
- public static void main(String[] s) {
- for (TestCase testCase : TestCase.values()) {
- testCase.test();
- }
- }
-
- public static enum TestCase {
- GET_TAG_AT {
- {
- referenceMap.put(1, ConstantPool.Tag.METHODREF);
- referenceMap.put(2, ConstantPool.Tag.CLASS);
- referenceMap.put(4, ConstantPool.Tag.UTF8);
- referenceMap.put(10, ConstantPool.Tag.NAMEANDTYPE);
- referenceMap.put(13, ConstantPool.Tag.LONG);
- referenceMap.put(15, ConstantPool.Tag.INTEGER);
- referenceMap.put(16, ConstantPool.Tag.INTERFACEMETHODREF);
- referenceMap.put(21, ConstantPool.Tag.DOUBLE);
- referenceMap.put(23, ConstantPool.Tag.STRING);
- referenceMap.put(25, ConstantPool.Tag.INVOKEDYNAMIC);
- referenceMap.put(29, ConstantPool.Tag.METHODHANDLE);
- referenceMap.put(30, ConstantPool.Tag.METHODTYPE);
- referenceMap.put(48, ConstantPool.Tag.FIELDREF);
- referenceMap.put(52, ConstantPool.Tag.FLOAT);
- }
- @Override
- void testIndex(int cpi, Object reference) {
- ConstantPool.Tag tagToVerify = CP.getTagAt(cpi);
- ConstantPool.Tag tagToRefer = (ConstantPool.Tag) reference;
- String msg = String.format("Method getTagAt works not as expected"
- + "at CP entry #%d: got CP tag %s, but should be %s",
- cpi, tagToVerify.name(), tagToRefer.name());
- Asserts.assertEquals(tagToVerify, tagToRefer, msg);
- }
- },
- GET_CLASS_REF_INDEX_AT {
- {
- referenceMap.put(1, 3);
- referenceMap.put(16, 17);
- referenceMap.put(32, 35);
- referenceMap.put(34, 3);
- referenceMap.put(48, 2);
- }
- @Override
- void testIndex(int cpi, Object reference) {
- int indexToVerify = CP.getClassRefIndexAt(cpi);
- int indexToRefer = (int) reference;
- String msg = String.format("Method getClassRefIndexAt works not"
- + " as expected at CP entry #%d:"
- + " got index %d, but should be %d",
- cpi, indexToVerify, indexToRefer);
- Asserts.assertEquals(indexToVerify, indexToRefer, msg);
- }
- },
- GET_NAME_AND_TYPE_REF_INDEX_AT {
- {
- referenceMap.put(1, 10);
- referenceMap.put(16, 18);
- referenceMap.put(25, 26);
- referenceMap.put(32, 36);
- referenceMap.put(34, 37);
- referenceMap.put(48, 49);
- }
- @Override
- void testIndex(int cpi, Object reference) {
- int indexToRefer = (int) reference;
- int indexToVerify = CP.getNameAndTypeRefIndexAt(cpi);
- String msg = String.format("Method getNameAndTypeRefIndexAt works"
- + " not as expected at CP entry #%d:"
- + " got index %d, but should be %d",
- cpi, indexToVerify, indexToRefer);
- Asserts.assertEquals(indexToVerify, indexToRefer, msg);
- }
- },
- GET_NAME_AND_TYPE_REF_INFO_AT {
- {
- referenceMap.put(10, new String[]{"<init>", "()V"});
- referenceMap.put(18, new String[]{"run", "()V"});
- referenceMap.put(26, new String[]{"accept", "()Ljava/util/function/Consumer;"});
- referenceMap.put(36, new String[]{"metafactory",
- "(Ljava/lang/invoke/MethodHandles$Lookup;"
- + "Ljava/lang/String;Ljava/lang/invoke/MethodType;"
- + "Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;"
- + "Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"});
- referenceMap.put(37, new String[]{"toString", "()Ljava/lang/String;"});
- referenceMap.put(49, new String[]{"myField", "I"});
- }
- @Override
- void testIndex(int cpi, Object reference) {
- String[] natInfo = CP.getNameAndTypeRefInfoAt(cpi);
- String msg = String.format("Method getNameAndTypeRefInfoAt"
- + " works not as expected at CP entry #%d:"
- + " returned value should not be null", cpi);
- Asserts.assertNotNull(natInfo, msg);
- String[] castedReference = (String[]) reference;
- int natInfoLength = natInfo.length;
- msg = String.format("Method getNameAndTypeRefInfoAt"
- + " works not as expected at CP entry #%d:"
- + " length of the returned string array is %d, but should be 2",
- cpi, natInfoLength);
- Asserts.assertEquals(natInfoLength, 2, msg);
- String[] nameOrType = new String[]{"name", "type"};
- for (int i = 0; i < 2; i++) {
- String infoToVerify = natInfo[i];
- String infoToRefer = castedReference[i];
- msg = String.format("Method getNameAndTypeRefInfoAt"
- + " works not as expected at CP entry #%d:"
- + " got %s info %s, but should be %s",
- cpi, nameOrType[i], infoToVerify, infoToRefer);
- Asserts.assertEquals(infoToVerify, infoToRefer, msg);
- }
- }
- };
-
- protected final Map<Integer, Object> referenceMap;
- TestCase() {
- this.referenceMap = new HashMap<>();
- }
- abstract void testIndex(int cpi, Object reference);
- public void test() {
- referenceMap.forEach(this::testIndex);
- }
- }
-}
--- a/jdk/test/sun/reflect/constantPool/ConstantPoolTestDummy.jasm Fri Apr 15 14:29:02 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * 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.
- */
-
-package sun/reflect/constantPool;
-
-super public #2; //class ConstantPoolTestDummy
- version 52:0
-{
-
-// Actually, only first 13 constant pool entries are actually used by the class
-// and its methods. All the rest are added just for the testing of getTagAt method
-// and getNameAndTypeRefIndexAt method.
-
-const #1 = Method #3.#10; // java/lang/Object."<init>":"()V"
-const #2 = class #11; // ConstantPoolTestDummy
-const #3 = class #12; // java/lang/Object
-const #4 = Asciz "<init>";
-const #5 = Asciz "()V";
-const #6 = Asciz "Code";
-const #7 = Asciz "LineNumberTable";
-const #8 = Asciz "SourceFile";
-const #9 = Asciz "ConstantPoolTestDummy.java";
-const #10 = NameAndType #4:#5; // "<init>":"()V"
-const #11 = Asciz "sun/reflect/constantPool/ConstantPoolTestDummy";
-const #12 = Asciz "java/lang/Object";
-const #13 = long 6l;
-const #15 = int 1;
-const #16 = InterfaceMethod #17.#18; // java/lang/Runnable.run:"()V"
-const #17 = class #19; // java/lang/Runnable
-const #18 = NameAndType #20:#5; // run:"()V"
-const #19 = Asciz "java/lang/Runnable";
-const #20 = Asciz "run";
-const #21 = double 1.45d;
-const #23 = String #24; // "Hello"
-const #24 = Asciz "Hello";
-const #25 = InvokeDynamic 0:#26; // REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;":accept:"()Ljava/util/function/Consumer;" MethodType "(Ljava/lang/Object;)V", MethodHandle REF_invokeVirtual:java/lang/Object.toString:"()Ljava/lang/String;", MethodType "(Ljava/lang/Object;)V"
-const #26 = NameAndType #27:#28; // accept:"()Ljava/util/function/Consumer;"
-const #27 = Asciz "accept";
-const #28 = Asciz "()Ljava/util/function/Consumer;";
-const #29 = MethodHandle 6:#32; // REF_invokeStatic:java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
-const #30 = MethodType #33; // "(Ljava/lang/Object;)V"
-const #31 = MethodHandle 5:#34; // REF_invokeVirtual:java/lang/Object.toString:"()Ljava/lang/String;"
-const #32 = Method #35.#36; // java/lang/invoke/LambdaMetafactory.metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
-const #33 = Asciz "(Ljava/lang/Object;)V";
-const #34 = Method #3.#37; // java/lang/Object.toString:"()Ljava/lang/String;"
-const #35 = class #38; // java/lang/invoke/LambdaMetafactory
-const #36 = NameAndType #39:#40; // metafactory:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
-const #37 = NameAndType #41:#42; // toString:"()Ljava/lang/String;"
-const #38 = Asciz "java/lang/invoke/LambdaMetafactory";
-const #39 = Asciz "metafactory";
-const #40 = Asciz "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;";
-const #41 = Asciz "toString";
-const #42 = Asciz "()Ljava/lang/String;";
-const #43 = class #46; // java/lang/invoke/MethodHandles$Lookup
-const #44 = Asciz "Lookup";
-const #45 = class #47; // java/lang/invoke/MethodHandles
-const #46 = Asciz "java/lang/invoke/MethodHandles$Lookup";
-const #47 = Asciz "java/lang/invoke/MethodHandles";
-const #48 = Field #2.#49; // sun/reflect/constantPool/ConstantPoolTestDummy.myField:"I"
-const #49 = NameAndType #50:#51; // myField:"I"
-const #50 = Asciz "myField";
-const #51 = Asciz "I";
-const #52 = float 1.34f;
-
-public Method #4:#5 // "<init>":"()V"
-
- stack 1 locals 1
-{
-3 0: aload_0;
- 1: invokespecial #1; // Method java/lang/Object."<init>":"()V";
- 4: return;
-}
-
-public static final InnerClass #44= #43 of #45; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
-
-BootstrapMethod #29 #30 #31 #30;
-
-} // end Class ConstantPoolTestDummy
--- a/jdk/test/tools/launcher/modules/addexports/AddExportsTest.java Fri Apr 15 14:29:02 2016 +0100
+++ b/jdk/test/tools/launcher/modules/addexports/AddExportsTest.java Fri Apr 15 16:19:15 2016 +0100
@@ -107,7 +107,7 @@
public void testSanity() throws Exception {
int exitValue
- = executeTestJava("-XaddExports:java.base/sun.reflect=ALL-UNNAMED",
+ = executeTestJava("-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED",
"-version")
.outputTo(System.out)
.errorTo(System.out)
@@ -207,8 +207,8 @@
public void testWithDuplicateOption() throws Exception {
int exitValue
- = executeTestJava("-XaddExports:java.base/sun.reflect=ALL-UNNAMED",
- "-XaddExports:java.base/sun.reflect=ALL-UNNAMED",
+ = executeTestJava("-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED",
+ "-XaddExports:java.base/jdk.internal.reflect=ALL-UNNAMED",
"-version")
.outputTo(System.out)
.errorTo(System.out)