13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoader.hpp"
27 #include "classfile/javaAssertions.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "gc_interface/collectedHeap.inline.hpp"
33 #include "memory/oopFactory.hpp"
34 #include "memory/universe.inline.hpp"
35 #include "oops/fieldStreams.hpp"
36 #include "oops/instanceKlass.hpp"
37 #include "oops/objArrayKlass.hpp"
38 #include "oops/method.hpp"
39 #include "prims/jvm.h"
40 #include "prims/jvm_misc.hpp"
41 #include "prims/jvmtiExport.hpp"
42 #include "prims/jvmtiThreadState.hpp"
43 #include "prims/nativeLookup.hpp"
44 #include "prims/privilegedStack.hpp"
45 #include "runtime/arguments.hpp"
46 #include "runtime/dtraceJSDT.hpp"
47 #include "runtime/handles.inline.hpp"
48 #include "runtime/init.hpp"
49 #include "runtime/interfaceSupport.hpp"
50 #include "runtime/java.hpp"
51 #include "runtime/javaCalls.hpp"
52 #include "runtime/jfieldIDWorkaround.hpp"
648
649 JVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len))
650 JVMWrapper("JVM_GetLastErrorString");
651 return (jint)os::lasterror(buf, len);
652 JVM_END
653
654
655 // java.io.File ///////////////////////////////////////////////////////////////
656
657 JVM_LEAF(char*, JVM_NativePath(char* path))
658 JVMWrapper2("JVM_NativePath (%s)", path);
659 return os::native_path(path);
660 JVM_END
661
662
663 // Misc. class handling ///////////////////////////////////////////////////////////
664
665
666 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
667 JVMWrapper("JVM_GetCallerClass");
668 Klass* k = thread->security_get_caller_class(depth);
669 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
670 JVM_END
671
672
673 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
674 JVMWrapper("JVM_FindPrimitiveClass");
675 oop mirror = NULL;
676 BasicType t = name2type(utf);
677 if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
678 mirror = Universe::java_mirror(t);
679 }
680 if (mirror == NULL) {
681 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
682 } else {
683 return (jclass) JNIHandles::make_local(env, mirror);
684 }
685 JVM_END
686
687
688 JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls))
689 JVMWrapper("JVM_ResolveClass");
3143
3144
3145 // Utility object for collecting method holders walking down the stack
3146 class KlassLink: public ResourceObj {
3147 public:
3148 KlassHandle klass;
3149 KlassLink* next;
3150
3151 KlassLink(KlassHandle k) { klass = k; next = NULL; }
3152 };
3153
3154
3155 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
3156 JVMWrapper("JVM_GetClassContext");
3157 ResourceMark rm(THREAD);
3158 JvmtiVMObjectAllocEventCollector oam;
3159 // Collect linked list of (handles to) method holders
3160 KlassLink* first = NULL;
3161 KlassLink* last = NULL;
3162 int depth = 0;
3163
3164 for(vframeStream vfst(thread); !vfst.at_end(); vfst.security_get_caller_frame(1)) {
3165 // Native frames are not returned
3166 if (!vfst.method()->is_native()) {
3167 Klass* holder = vfst.method()->method_holder();
3168 assert(holder->is_klass(), "just checking");
3169 depth++;
3170 KlassLink* l = new KlassLink(KlassHandle(thread, holder));
3171 if (first == NULL) {
3172 first = last = l;
3173 } else {
3174 last->next = l;
3175 last = l;
3176 }
3177 }
3178 }
3179
3180 // Create result array of type [Ljava/lang/Class;
3181 objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), depth, CHECK_NULL);
3182 // Fill in mirrors corresponding to method holders
3183 int index = 0;
3184 while (first != NULL) {
3185 result->obj_at_put(index++, first->klass()->java_mirror());
3186 first = first->next;
3187 }
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoader.hpp"
27 #include "classfile/javaAssertions.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "gc_interface/collectedHeap.inline.hpp"
33 #include "interpreter/bytecode.hpp"
34 #include "memory/oopFactory.hpp"
35 #include "memory/universe.inline.hpp"
36 #include "oops/fieldStreams.hpp"
37 #include "oops/instanceKlass.hpp"
38 #include "oops/objArrayKlass.hpp"
39 #include "oops/method.hpp"
40 #include "prims/jvm.h"
41 #include "prims/jvm_misc.hpp"
42 #include "prims/jvmtiExport.hpp"
43 #include "prims/jvmtiThreadState.hpp"
44 #include "prims/nativeLookup.hpp"
45 #include "prims/privilegedStack.hpp"
46 #include "runtime/arguments.hpp"
47 #include "runtime/dtraceJSDT.hpp"
48 #include "runtime/handles.inline.hpp"
49 #include "runtime/init.hpp"
50 #include "runtime/interfaceSupport.hpp"
51 #include "runtime/java.hpp"
52 #include "runtime/javaCalls.hpp"
53 #include "runtime/jfieldIDWorkaround.hpp"
649
650 JVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len))
651 JVMWrapper("JVM_GetLastErrorString");
652 return (jint)os::lasterror(buf, len);
653 JVM_END
654
655
656 // java.io.File ///////////////////////////////////////////////////////////////
657
658 JVM_LEAF(char*, JVM_NativePath(char* path))
659 JVMWrapper2("JVM_NativePath (%s)", path);
660 return os::native_path(path);
661 JVM_END
662
663
664 // Misc. class handling ///////////////////////////////////////////////////////////
665
666
667 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
668 JVMWrapper("JVM_GetCallerClass");
669
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;
714 JVM_END
715
716
717 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
718 JVMWrapper("JVM_FindPrimitiveClass");
719 oop mirror = NULL;
720 BasicType t = name2type(utf);
721 if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
722 mirror = Universe::java_mirror(t);
723 }
724 if (mirror == NULL) {
725 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
726 } else {
727 return (jclass) JNIHandles::make_local(env, mirror);
728 }
729 JVM_END
730
731
732 JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls))
733 JVMWrapper("JVM_ResolveClass");
3187
3188
3189 // Utility object for collecting method holders walking down the stack
3190 class KlassLink: public ResourceObj {
3191 public:
3192 KlassHandle klass;
3193 KlassLink* next;
3194
3195 KlassLink(KlassHandle k) { klass = k; next = NULL; }
3196 };
3197
3198
3199 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
3200 JVMWrapper("JVM_GetClassContext");
3201 ResourceMark rm(THREAD);
3202 JvmtiVMObjectAllocEventCollector oam;
3203 // Collect linked list of (handles to) method holders
3204 KlassLink* first = NULL;
3205 KlassLink* last = NULL;
3206 int depth = 0;
3207 vframeStream vfst(thread);
3208
3209 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) {
3210 // This must only be called from SecurityManager.getClassContext
3211 Method* m = vfst.method();
3212 if (!(m->method_holder() == SystemDictionary::SecurityManager_klass() &&
3213 m->name() == vmSymbols::getClassContext_name() &&
3214 m->signature() == vmSymbols::void_class_array_signature())) {
3215 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext");
3216 }
3217 }
3218
3219 // Collect method holders
3220 for (; !vfst.at_end(); vfst.security_next()) {
3221 Method* m = vfst.method();
3222 // Native frames are not returned
3223 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) {
3224 Klass* holder = m->method_holder();
3225 assert(holder->is_klass(), "just checking");
3226 depth++;
3227 KlassLink* l = new KlassLink(KlassHandle(thread, holder));
3228 if (first == NULL) {
3229 first = last = l;
3230 } else {
3231 last->next = l;
3232 last = l;
3233 }
3234 }
3235 }
3236
3237 // Create result array of type [Ljava/lang/Class;
3238 objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), depth, CHECK_NULL);
3239 // Fill in mirrors corresponding to method holders
3240 int index = 0;
3241 while (first != NULL) {
3242 result->obj_at_put(index++, first->klass()->java_mirror());
3243 first = first->next;
3244 }
|