8179424: Remove terminally deprecated sun.reflect.Reflection.getCallerClass
authorchegar
Fri, 22 Dec 2017 15:55:29 +0000
changeset 48477 b7af6f568d00
parent 48476 ca9489245872
child 48478 f3907e64eea2
8179424: Remove terminally deprecated sun.reflect.Reflection.getCallerClass Reviewed-by: alanb, dfuchs, dholmes, lancea, mchung, rriggs
make/mapfiles/libjava/mapfile-vers
make/mapfiles/libjava/reorder-sparc
make/mapfiles/libjava/reorder-sparcv9
make/mapfiles/libjava/reorder-x86
src/hotspot/share/include/jvm.h
src/hotspot/share/prims/jvm.cpp
src/java.base/share/classes/jdk/internal/reflect/Reflection.java
src/java.base/share/native/libjava/Reflection.c
src/jdk.unsupported/share/classes/sun/reflect/Reflection.java
test/jdk/jdk/internal/reflect/Reflection/GetCallerClassWithDepth.java
test/jdk/sun/reflect/Reflection/GetCallerClassWithDepth.java
test/langtools/tools/jdeps/jdkinternals/RemovedJDKInternals.java
test/langtools/tools/jdeps/jdkinternals/patches/jdk.unsupported/sun/reflect/Reflection.java
test/langtools/tools/jdeps/jdkinternals/src/p/Main.java
--- a/make/mapfiles/libjava/mapfile-vers	Wed Dec 20 11:00:07 2017 -0800
+++ b/make/mapfiles/libjava/mapfile-vers	Fri Dec 22 15:55:29 2017 +0000
@@ -257,7 +257,6 @@
 		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_latestUserDefinedLoader0;
                 Java_jdk_internal_misc_VM_getuid;
--- a/make/mapfiles/libjava/reorder-sparc	Wed Dec 20 11:00:07 2017 -0800
+++ b/make/mapfiles/libjava/reorder-sparc	Fri Dec 22 15:55:29 2017 +0000
@@ -27,7 +27,6 @@
 text: .text%Java_java_io_FileOutputStream_initIDs;
 text: .text%Java_java_lang_System_setIn0;
 text: .text%Java_sun_reflect_Reflection_getCallerClass__;
-text: .text%Java_sun_reflect_Reflection_getCallerClass__I;
 text: .text%Java_java_lang_Class_forName0;
 text: .text%Java_java_lang_Object_getClass;
 text: .text%Java_sun_reflect_Reflection_getClassAccessFlags;
--- a/make/mapfiles/libjava/reorder-sparcv9	Wed Dec 20 11:00:07 2017 -0800
+++ b/make/mapfiles/libjava/reorder-sparcv9	Fri Dec 22 15:55:29 2017 +0000
@@ -26,7 +26,6 @@
 text: .text%Java_java_io_FileOutputStream_initIDs;
 text: .text%Java_java_lang_System_setIn0;
 text: .text%Java_sun_reflect_Reflection_getCallerClass__;
-text: .text%Java_sun_reflect_Reflection_getCallerClass__I;
 text: .text%Java_java_lang_Class_forName0;
 text: .text%Java_java_lang_String_intern;
 text: .text%Java_java_lang_StringUTF16_isBigEndian;
--- a/make/mapfiles/libjava/reorder-x86	Wed Dec 20 11:00:07 2017 -0800
+++ b/make/mapfiles/libjava/reorder-x86	Fri Dec 22 15:55:29 2017 +0000
@@ -27,7 +27,6 @@
 text: .text%Java_java_io_FileOutputStream_initIDs;
 text: .text%Java_java_lang_System_setIn0;
 text: .text%Java_sun_reflect_Reflection_getCallerClass__;
-text: .text%Java_sun_reflect_Reflection_getCallerClass__I;
 text: .text%Java_java_lang_Class_forName0;
 text: .text%Java_java_lang_String_intern;
 text: .text%Java_java_lang_StringUTF16_isBigEndian;
--- a/src/hotspot/share/include/jvm.h	Wed Dec 20 11:00:07 2017 -0800
+++ b/src/hotspot/share/include/jvm.h	Fri Dec 22 15:55:29 2017 +0000
@@ -317,23 +317,18 @@
 JNIEXPORT jobject JNICALL
 JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim);
 
-/*
- * java.lang.Class and java.lang.ClassLoader
- */
-
-#define JVM_CALLER_DEPTH -1
 
 /*
  * Returns the immediate caller class of the native method invoking
  * JVM_GetCallerClass.  The Method.invoke and other frames due to
  * reflection machinery are skipped.
  *
- * The depth parameter must be -1 (JVM_DEPTH). The caller is expected
- * to be marked with sun.reflect.CallerSensitive.  The JVM will throw
- * an error if it is not marked propertly.
+ * The caller is expected to be marked with
+ * jdk.internal.reflect.CallerSensitive. The JVM will throw an
+ * error if it is not marked properly.
  */
 JNIEXPORT jclass JNICALL
-JVM_GetCallerClass(JNIEnv *env, int depth);
+JVM_GetCallerClass(JNIEnv *env);
 
 
 /*
--- a/src/hotspot/share/prims/jvm.cpp	Wed Dec 20 11:00:07 2017 -0800
+++ b/src/hotspot/share/prims/jvm.cpp	Fri Dec 22 15:55:29 2017 +0000
@@ -678,17 +678,9 @@
 // Misc. class handling ///////////////////////////////////////////////////////////
 
 
-JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
+JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
   JVMWrapper("JVM_GetCallerClass");
 
-  // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or
-  // sun.reflect.Reflection.getCallerClass with a depth parameter is provided
-  // temporarily for existing code to use until a replacement API is defined.
-  if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) {
-    Klass* k = thread->security_get_caller_class(depth);
-    return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
-  }
-
   // Getting the class of the caller frame.
   //
   // The call stack at this point looks something like this:
--- a/src/java.base/share/classes/jdk/internal/reflect/Reflection.java	Wed Dec 20 11:00:07 2017 -0800
+++ b/src/java.base/share/classes/jdk/internal/reflect/Reflection.java	Fri Dec 22 15:55:29 2017 +0000
@@ -64,14 +64,6 @@
     @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
--- a/src/java.base/share/native/libjava/Reflection.c	Wed Dec 20 11:00:07 2017 -0800
+++ b/src/java.base/share/native/libjava/Reflection.c	Fri Dec 22 15:55:29 2017 +0000
@@ -30,13 +30,7 @@
 JNIEXPORT jclass JNICALL
 Java_jdk_internal_reflect_Reflection_getCallerClass__(JNIEnv *env, jclass unused)
 {
-    return JVM_GetCallerClass(env, JVM_CALLER_DEPTH);
-}
-
-JNIEXPORT jclass JNICALL
-Java_jdk_internal_reflect_Reflection_getCallerClass__I(JNIEnv *env, jclass unused, jint depth)
-{
-    return JVM_GetCallerClass(env, depth);
+    return JVM_GetCallerClass(env);
 }
 
 JNIEXPORT jint JNICALL
--- a/src/jdk.unsupported/share/classes/sun/reflect/Reflection.java	Wed Dec 20 11:00:07 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2001, 2017, 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)
-    @SuppressWarnings("removal") // Reflection.getCallerClass
-    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);
-    }
-}
--- a/test/jdk/jdk/internal/reflect/Reflection/GetCallerClassWithDepth.java	Wed Dec 20 11:00:07 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +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 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);
-                }
-            }
-        }
-    }
-}
--- a/test/jdk/sun/reflect/Reflection/GetCallerClassWithDepth.java	Wed Dec 20 11:00:07 2017 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +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 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();
-        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);
-                }
-            }
-        }
-    }
-}
--- a/test/langtools/tools/jdeps/jdkinternals/RemovedJDKInternals.java	Wed Dec 20 11:00:07 2017 -0800
+++ b/test/langtools/tools/jdeps/jdkinternals/RemovedJDKInternals.java	Fri Dec 22 15:55:29 2017 +0000
@@ -85,7 +85,8 @@
                 .reference("p.Main", "java.lang.Object", "java.base")
                 .reference("p.Main", "java.util.Iterator", "java.base")
                 .reference("p.S", "java.lang.Object", "java.base")
-                .jdkInternal("p.Main", "sun.reflect.Reflection", "jdk.unsupported")
+                .jdkInternal("p.Main", "sun.reflect.ReflectionFactory", "jdk.unsupported")
+                .removedJdkInternal("p.Main", "sun.reflect.Reflection")
                 .removedJdkInternal("p.Main", "com.sun.image.codec.jpeg.JPEGCodec")
                 .removedJdkInternal("p.Main", "sun.misc.Service")
                 .removedJdkInternal("p.Main", "sun.misc.SoftCache")
@@ -118,7 +119,8 @@
         "com.sun.image.codec.jpeg.JPEGCodec", "Use javax.imageio @since 1.4",
         "sun.misc.Service", "Use java.util.ServiceLoader @since 1.6",
         "sun.misc.SoftCache", "Removed. See http://openjdk.java.net/jeps/260",
-        "sun.reflect.Reflection", "Use java.lang.StackWalker @since 9"
+        "sun.reflect.Reflection", "Use java.lang.StackWalker @since 9",
+        "sun.reflect.ReflectionFactory", "See http://openjdk.java.net/jeps/260"
     );
 
     @Test
@@ -139,6 +141,8 @@
             int pos = line.indexOf("Use ");
             if (pos < 0)
                 pos = line.indexOf("Removed. ");
+            if (pos < 0)
+                pos = line.indexOf("See ");
 
             assertTrue(pos > 0);
             String name = line.substring(0, pos).trim();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/jdeps/jdkinternals/patches/jdk.unsupported/sun/reflect/Reflection.java	Fri Dec 22 15:55:29 2017 +0000
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017, 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;
+
+/*
+ * JDK removed internal API
+ */
+public class Reflection {
+    public static Class<?> getCallerClass(int depth) {
+        return null;
+    }
+}
--- a/test/langtools/tools/jdeps/jdkinternals/src/p/Main.java	Wed Dec 20 11:00:07 2017 -0800
+++ b/test/langtools/tools/jdeps/jdkinternals/src/p/Main.java	Fri Dec 22 15:55:29 2017 +0000
@@ -27,10 +27,14 @@
 import sun.misc.Service;
 import sun.misc.SoftCache;
 import sun.reflect.Reflection;
+import sun.reflect.ReflectionFactory;
 
 public class Main {
     public static void main() {
         // in jdk.unsupported
+        ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
+
+        // removed from jdk.unsupported in JDK 11
         Class<?> caller = Reflection.getCallerClass(2);
 
         // removed