8161379: Force inline methods calling Reflection.getCallerClass
Reviewed-by: shade, mchung
--- a/jdk/src/java.base/share/classes/java/lang/Class.java Fri Aug 05 10:23:28 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/Class.java Sat Aug 06 00:34:50 2016 +0200
@@ -70,6 +70,7 @@
import jdk.internal.reflect.ConstantPool;
import jdk.internal.reflect.Reflection;
import jdk.internal.reflect.ReflectionFactory;
+import jdk.internal.vm.annotation.ForceInline;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.repository.ClassRepository;
@@ -802,6 +803,7 @@
* @see java.lang.RuntimePermission
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public ClassLoader getClassLoader() {
ClassLoader cl = getClassLoader0();
if (cl == null)
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Fri Aug 05 10:23:28 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java Sat Aug 06 00:34:50 2016 +0200
@@ -30,6 +30,7 @@
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
+import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
import sun.invoke.empty.Empty;
import sun.invoke.util.ValueConversions;
@@ -44,7 +45,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.invoke.LambdaForm.*;
@@ -1246,6 +1246,7 @@
}
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
private static boolean checkCallerClass(Class<?> expected) {
// This method is called via MH_checkCallerClass and so it's correct to ask for the immediate caller here.
Class<?> actual = Reflection.getCallerClass();
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Fri Aug 05 10:23:28 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Sat Aug 06 00:34:50 2016 +0200
@@ -29,6 +29,7 @@
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
+import jdk.internal.vm.annotation.ForceInline;
import sun.invoke.util.ValueConversions;
import sun.invoke.util.VerifyAccess;
import sun.invoke.util.Wrapper;
@@ -104,6 +105,7 @@
* @return a lookup object for the caller of this method, with private access
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public static Lookup lookup() {
return new Lookup(Reflection.getCallerClass());
}
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java Fri Aug 05 10:23:28 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Constructor.java Sat Aug 06 00:34:50 2016 +0200
@@ -29,6 +29,7 @@
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.ConstructorAccessor;
import jdk.internal.reflect.Reflection;
+import jdk.internal.vm.annotation.ForceInline;
import sun.reflect.annotation.TypeAnnotation;
import sun.reflect.annotation.TypeAnnotationParser;
import sun.reflect.generics.repository.ConstructorRepository;
@@ -435,6 +436,7 @@
* by this method fails.
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public T newInstance(Object ... initargs)
throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Field.java Fri Aug 05 10:23:28 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Field.java Sat Aug 06 00:34:50 2016 +0200
@@ -29,6 +29,7 @@
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.FieldAccessor;
import jdk.internal.reflect.Reflection;
+import jdk.internal.vm.annotation.ForceInline;
import sun.reflect.generics.repository.FieldRepository;
import sun.reflect.generics.factory.CoreReflectionFactory;
import sun.reflect.generics.factory.GenericsFactory;
@@ -396,6 +397,7 @@
* by this method fails.
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public Object get(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -429,6 +431,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public boolean getBoolean(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -462,6 +465,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public byte getByte(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -497,6 +501,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public char getChar(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -532,6 +537,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public short getShort(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -567,6 +573,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public int getInt(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -602,6 +609,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public long getLong(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -637,6 +645,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public float getFloat(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -672,6 +681,7 @@
* @see Field#get
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public double getDouble(Object obj)
throws IllegalArgumentException, IllegalAccessException
{
@@ -749,6 +759,7 @@
* by this method fails.
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void set(Object obj, Object value)
throws IllegalArgumentException, IllegalAccessException
{
@@ -784,6 +795,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setBoolean(Object obj, boolean z)
throws IllegalArgumentException, IllegalAccessException
{
@@ -819,6 +831,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setByte(Object obj, byte b)
throws IllegalArgumentException, IllegalAccessException
{
@@ -854,6 +867,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setChar(Object obj, char c)
throws IllegalArgumentException, IllegalAccessException
{
@@ -889,6 +903,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setShort(Object obj, short s)
throws IllegalArgumentException, IllegalAccessException
{
@@ -924,6 +939,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setInt(Object obj, int i)
throws IllegalArgumentException, IllegalAccessException
{
@@ -959,6 +975,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setLong(Object obj, long l)
throws IllegalArgumentException, IllegalAccessException
{
@@ -994,6 +1011,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setFloat(Object obj, float f)
throws IllegalArgumentException, IllegalAccessException
{
@@ -1029,6 +1047,7 @@
* @see Field#set
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
public void setDouble(Object obj, double d)
throws IllegalArgumentException, IllegalAccessException
{
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Method.java Fri Aug 05 10:23:28 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Method.java Sat Aug 06 00:34:50 2016 +0200
@@ -30,6 +30,7 @@
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.MethodAccessor;
import jdk.internal.reflect.Reflection;
+import jdk.internal.vm.annotation.ForceInline;
import sun.reflect.annotation.ExceptionProxy;
import sun.reflect.annotation.TypeNotPresentExceptionProxy;
import sun.reflect.generics.repository.MethodRepository;
@@ -517,6 +518,7 @@
* provoked by this method fails.
*/
@CallerSensitive
+ @ForceInline // to ensure Reflection.getCallerClass optimization
@HotSpotIntrinsicCandidate
public Object invoke(Object obj, Object... args)
throws IllegalAccessException, IllegalArgumentException,