From d292b1fda487f80273ba1f0e5a19c4130cf85f08 Mon Sep 17 00:00:00 2001 From: dholmes Date: Tue, 8 Oct 2013 02:56:06 -0400 Subject: [PATCH] 8026025: JVM_GetCallerClass allows Reflection.getCallerClass(int depth) to use Reviewed-by: alanb, dholmes, twisti Contributed-by: mandy.chung@oracle.com --- src/share/vm/prims/jvm.cpp | 9 ++++----- src/share/vm/prims/jvm.h | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp index 23635a3d2..a757e1948 100644 --- a/src/share/vm/prims/jvm.cpp +++ b/src/share/vm/prims/jvm.cpp @@ -668,13 +668,12 @@ JVM_END JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth)) JVMWrapper("JVM_GetCallerClass"); - // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation. - if (SystemDictionary::reflect_CallerSensitive_klass() == NULL) { + // 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()); - } else { - // Basic handshaking with Java_sun_reflect_Reflection_getCallerClass - assert(depth == -1, "wrong handshake depth"); } // Getting the class of the caller frame. diff --git a/src/share/vm/prims/jvm.h b/src/share/vm/prims/jvm.h index 6248f4d79..ef57a9d2b 100644 --- a/src/share/vm/prims/jvm.h +++ b/src/share/vm/prims/jvm.h @@ -374,6 +374,9 @@ JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim); /* * java.lang.Class and java.lang.ClassLoader */ + +#define JVM_CALLER_DEPTH -1 + /* * Returns the class in which the code invoking the native method * belongs. -- GitLab