Mercurial > hg > truffle
comparison src/share/vm/prims/jvm.cpp @ 8870:cd9ad42dfde0
Merge
author | bharadwaj |
---|---|
date | Fri, 29 Mar 2013 20:52:01 -0700 |
parents | 1916ca1dec2f 16885e702c88 |
children | b9a918201d47 92ef81e2f571 b295e132102d |
comparison
equal
deleted
inserted
replaced
8836:d26674db4d91 | 8870:cd9ad42dfde0 |
---|---|
28 #include "classfile/javaClasses.hpp" | 28 #include "classfile/javaClasses.hpp" |
29 #include "classfile/symbolTable.hpp" | 29 #include "classfile/symbolTable.hpp" |
30 #include "classfile/systemDictionary.hpp" | 30 #include "classfile/systemDictionary.hpp" |
31 #include "classfile/vmSymbols.hpp" | 31 #include "classfile/vmSymbols.hpp" |
32 #include "gc_interface/collectedHeap.inline.hpp" | 32 #include "gc_interface/collectedHeap.inline.hpp" |
33 #include "interpreter/bytecode.hpp" | |
33 #include "memory/oopFactory.hpp" | 34 #include "memory/oopFactory.hpp" |
34 #include "memory/universe.inline.hpp" | 35 #include "memory/universe.inline.hpp" |
35 #include "oops/fieldStreams.hpp" | 36 #include "oops/fieldStreams.hpp" |
36 #include "oops/instanceKlass.hpp" | 37 #include "oops/instanceKlass.hpp" |
37 #include "oops/objArrayKlass.hpp" | 38 #include "oops/objArrayKlass.hpp" |
663 // Misc. class handling /////////////////////////////////////////////////////////// | 664 // Misc. class handling /////////////////////////////////////////////////////////// |
664 | 665 |
665 | 666 |
666 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth)) | 667 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth)) |
667 JVMWrapper("JVM_GetCallerClass"); | 668 JVMWrapper("JVM_GetCallerClass"); |
668 Klass* k = thread->security_get_caller_class(depth); | 669 |
669 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror()); | 670 // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation. |
671 if (SystemDictionary::reflect_CallerSensitive_klass() == NULL) { | |
672 Klass* k = thread->security_get_caller_class(depth); | |
673 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror()); | |
674 } else { | |
675 // Basic handshaking with Java_sun_reflect_Reflection_getCallerClass | |
676 assert(depth == -1, "wrong handshake depth"); | |
677 } | |
678 | |
679 // Getting the class of the caller frame. | |
680 // | |
681 // The call stack at this point looks something like this: | |
682 // | |
683 // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ] | |
684 // [1] [ @CallerSensitive API.method ] | |
685 // [.] [ (skipped intermediate frames) ] | |
686 // [n] [ caller ] | |
687 vframeStream vfst(thread); | |
688 // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass | |
689 for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) { | |
690 Method* m = vfst.method(); | |
691 assert(m != NULL, "sanity"); | |
692 switch (n) { | |
693 case 0: | |
694 // This must only be called from Reflection.getCallerClass | |
695 if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) { | |
696 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetCallerClass must only be called from Reflection.getCallerClass"); | |
697 } | |
698 // fall-through | |
699 case 1: | |
700 // Frame 0 and 1 must be caller sensitive. | |
701 if (!m->caller_sensitive()) { | |
702 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n)); | |
703 } | |
704 break; | |
705 default: | |
706 if (!m->is_ignored_by_security_stack_walk()) { | |
707 // We have reached the desired frame; return the holder class. | |
708 return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror()); | |
709 } | |
710 break; | |
711 } | |
712 } | |
713 return NULL; | |
670 JVM_END | 714 JVM_END |
671 | 715 |
672 | 716 |
673 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf)) | 717 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf)) |
674 JVMWrapper("JVM_FindPrimitiveClass"); | 718 JVMWrapper("JVM_FindPrimitiveClass"); |
3206 JvmtiVMObjectAllocEventCollector oam; | 3250 JvmtiVMObjectAllocEventCollector oam; |
3207 // Collect linked list of (handles to) method holders | 3251 // Collect linked list of (handles to) method holders |
3208 KlassLink* first = NULL; | 3252 KlassLink* first = NULL; |
3209 KlassLink* last = NULL; | 3253 KlassLink* last = NULL; |
3210 int depth = 0; | 3254 int depth = 0; |
3211 | 3255 vframeStream vfst(thread); |
3212 for(vframeStream vfst(thread); !vfst.at_end(); vfst.security_get_caller_frame(1)) { | 3256 |
3257 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) { | |
3258 // This must only be called from SecurityManager.getClassContext | |
3259 Method* m = vfst.method(); | |
3260 if (!(m->method_holder() == SystemDictionary::SecurityManager_klass() && | |
3261 m->name() == vmSymbols::getClassContext_name() && | |
3262 m->signature() == vmSymbols::void_class_array_signature())) { | |
3263 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext"); | |
3264 } | |
3265 } | |
3266 | |
3267 // Collect method holders | |
3268 for (; !vfst.at_end(); vfst.security_next()) { | |
3269 Method* m = vfst.method(); | |
3213 // Native frames are not returned | 3270 // Native frames are not returned |
3214 if (!vfst.method()->is_native()) { | 3271 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) { |
3215 Klass* holder = vfst.method()->method_holder(); | 3272 Klass* holder = m->method_holder(); |
3216 assert(holder->is_klass(), "just checking"); | 3273 assert(holder->is_klass(), "just checking"); |
3217 depth++; | 3274 depth++; |
3218 KlassLink* l = new KlassLink(KlassHandle(thread, holder)); | 3275 KlassLink* l = new KlassLink(KlassHandle(thread, holder)); |
3219 if (first == NULL) { | 3276 if (first == NULL) { |
3220 first = last = l; | 3277 first = last = l; |