8026025: JVM_GetCallerClass allows Reflection.getCallerClass(int depth) to use

Tue, 08 Oct 2013 02:56:06 -0400

author
dholmes
date
Tue, 08 Oct 2013 02:56:06 -0400
changeset 5849
615d83933195
parent 5848
ac9cb1d5a202
child 5851
ced68a57cdbd

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 file | annotate | diff | comparison | revisions
src/share/vm/prims/jvm.h file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/prims/jvm.cpp	Mon Oct 07 12:20:28 2013 -0400
     1.2 +++ b/src/share/vm/prims/jvm.cpp	Tue Oct 08 02:56:06 2013 -0400
     1.3 @@ -668,13 +668,12 @@
     1.4  JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
     1.5    JVMWrapper("JVM_GetCallerClass");
     1.6  
     1.7 -  // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation.
     1.8 -  if (SystemDictionary::reflect_CallerSensitive_klass() == NULL) {
     1.9 +  // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or
    1.10 +  // sun.reflect.Reflection.getCallerClass with a depth parameter is provided
    1.11 +  // temporarily for existing code to use until a replacement API is defined.
    1.12 +  if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) {
    1.13      Klass* k = thread->security_get_caller_class(depth);
    1.14      return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
    1.15 -  } else {
    1.16 -    // Basic handshaking with Java_sun_reflect_Reflection_getCallerClass
    1.17 -    assert(depth == -1, "wrong handshake depth");
    1.18    }
    1.19  
    1.20    // Getting the class of the caller frame.
     2.1 --- a/src/share/vm/prims/jvm.h	Mon Oct 07 12:20:28 2013 -0400
     2.2 +++ b/src/share/vm/prims/jvm.h	Tue Oct 08 02:56:06 2013 -0400
     2.3 @@ -374,6 +374,9 @@
     2.4  /*
     2.5   * java.lang.Class and java.lang.ClassLoader
     2.6   */
     2.7 +
     2.8 +#define JVM_CALLER_DEPTH -1
     2.9 +
    2.10  /*
    2.11   * Returns the class in which the code invoking the native method
    2.12   * belongs.

mercurial