2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
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.
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
25 #include "incls/_precompiled.incl"
26 #include "incls/_jvm.cpp.incl"
30 NOTE about use of any ctor or function call that can trigger a safepoint/GC:
31 such ctors and calls MUST NOT come between an oop declaration/init and its
32 usage because if objects are move this may cause various memory stomps, bus
33 errors and segfaults. Here is a cookbook for causing so called "naked oop
36 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
37 JVMWrapper("JVM_GetClassDeclaredFields");
39 // Object address to be held directly in mirror & not visible to GC
40 oop mirror = JNIHandles::resolve_non_null(ofClass);
42 // If this ctor can hit a safepoint, moving objects around, then
43 ComplexConstructor foo;
45 // Boom! mirror may point to JUNK instead of the intended object
46 (some dereference of mirror)
48 // Here's another call that may block for GC, making mirror stale
49 MutexLocker ml(some_lock);
51 // And here's an initializer that can result in a stale oop
53 oop o = call_that_can_throw_exception(TRAPS);
56 The solution is to keep the oop declaration BELOW the ctor or function
57 call that might cause a GC, do another resolve to reassign the oop, or
58 consider use of a Handle instead of an oop so there is immunity from object
59 motion. But note that the "QUICK" entries below do not have a handlemark
60 and thus can only support use of handles passed in.
63 static void trace_class_resolution_impl(klassOop to_class, TRAPS) {
66 const char * source_file = NULL;
67 klassOop caller = NULL;
68 JavaThread* jthread = JavaThread::current();
69 if (jthread->has_last_Java_frame()) {
70 vframeStream vfst(jthread);
72 // scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames
73 symbolHandle access_controller = oopFactory::new_symbol_handle("java/security/AccessController", CHECK);
74 klassOop access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK);
75 symbolHandle privileged_action = oopFactory::new_symbol_handle("java/security/PrivilegedAction", CHECK);
76 klassOop privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK);
78 methodOop last_caller = NULL;
80 while (!vfst.at_end()) {
81 methodOop m = vfst.method();
82 if (!vfst.method()->method_holder()->klass_part()->is_subclass_of(SystemDictionary::classloader_klass())&&
83 !vfst.method()->method_holder()->klass_part()->is_subclass_of(access_controller_klass) &&
84 !vfst.method()->method_holder()->klass_part()->is_subclass_of(privileged_action_klass)) {
90 // if this is called from Class.forName0 and that is called from Class.forName,
91 // then print the caller of Class.forName. If this is Class.loadClass, then print
92 // that caller, otherwise keep quiet since this should be picked up elsewhere.
93 bool found_it = false;
95 instanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class() &&
96 vfst.method()->name() == vmSymbols::forName0_name()) {
99 instanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class() &&
100 vfst.method()->name() == vmSymbols::forName_name()) {
104 } else if (last_caller != NULL &&
105 instanceKlass::cast(last_caller->method_holder())->name() ==
106 vmSymbols::java_lang_ClassLoader() &&
107 (last_caller->name() == vmSymbols::loadClassInternal_name() ||
108 last_caller->name() == vmSymbols::loadClass_name())) {
111 if (found_it && !vfst.at_end()) {
113 caller = vfst.method()->method_holder();
114 line_number = vfst.method()->line_number_from_bci(vfst.bci());
115 symbolOop s = instanceKlass::cast(vfst.method()->method_holder())->source_file_name();
117 source_file = s->as_C_string();
121 if (caller != NULL) {
122 if (to_class != caller) {
123 const char * from = Klass::cast(caller)->external_name();
124 const char * to = Klass::cast(to_class)->external_name();
125 // print in a single call to reduce interleaving between threads
126 if (source_file != NULL) {
127 tty->print("RESOLVE %s %s %s:%d (explicit)\n", from, to, source_file, line_number);
129 tty->print("RESOLVE %s %s (explicit)\n", from, to);
135 static void trace_class_resolution(klassOop to_class) {
137 trace_class_resolution_impl(to_class, THREAD);
138 if (HAS_PENDING_EXCEPTION) {
139 CLEAR_PENDING_EXCEPTION;
143 // Wrapper to trace JVM functions
146 class JVMTraceWrapper : public StackObj {
148 JVMTraceWrapper(const char* format, ...) {
151 va_start(ap, format);
153 tty->vprint_cr(format, ap);
159 Histogram* JVMHistogram;
160 volatile jint JVMHistogram_lock = 0;
162 class JVMHistogramElement : public HistogramElement {
164 JVMHistogramElement(const char* name);
167 JVMHistogramElement::JVMHistogramElement(const char* elementName) {
171 while (Atomic::cmpxchg(1, &JVMHistogram_lock, 0) != 0) {
172 while (OrderAccess::load_acquire(&JVMHistogram_lock) != 0) {
174 if ( (WarnOnStalledSpinLock > 0)
175 && (count % WarnOnStalledSpinLock == 0)) {
176 warning("JVMHistogram_lock seems to be stalled");
181 if(JVMHistogram == NULL)
182 JVMHistogram = new Histogram("JVM Call Counts",100);
184 JVMHistogram->add_element(this);
185 Atomic::dec(&JVMHistogram_lock);
188 #define JVMCountWrapper(arg) \
189 static JVMHistogramElement* e = new JVMHistogramElement(arg); \
190 if (e != NULL) e->increment_count(); // Due to bug in VC++, we need a NULL check here eventhough it should never happen!
192 #define JVMWrapper(arg1) JVMCountWrapper(arg1); JVMTraceWrapper(arg1)
193 #define JVMWrapper2(arg1, arg2) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2)
194 #define JVMWrapper3(arg1, arg2, arg3) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3)
195 #define JVMWrapper4(arg1, arg2, arg3, arg4) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3, arg4)
197 #define JVMWrapper(arg1)
198 #define JVMWrapper2(arg1, arg2)
199 #define JVMWrapper3(arg1, arg2, arg3)
200 #define JVMWrapper4(arg1, arg2, arg3, arg4)
204 // Interface version /////////////////////////////////////////////////////////////////////
207 JVM_LEAF(jint, JVM_GetInterfaceVersion())
208 return JVM_INTERFACE_VERSION;
212 // java.lang.System //////////////////////////////////////////////////////////////////////
215 JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
216 JVMWrapper("JVM_CurrentTimeMillis");
217 return os::javaTimeMillis();
220 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
221 JVMWrapper("JVM_NanoTime");
222 return os::javaTimeNanos();
226 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
227 jobject dst, jint dst_pos, jint length))
228 JVMWrapper("JVM_ArrayCopy");
229 // Check if we have null pointers
230 if (src == NULL || dst == NULL) {
231 THROW(vmSymbols::java_lang_NullPointerException());
233 arrayOop s = arrayOop(JNIHandles::resolve_non_null(src));
234 arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst));
235 assert(s->is_oop(), "JVM_ArrayCopy: src not an oop");
236 assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop");
238 Klass::cast(s->klass())->copy_array(s, src_pos, d, dst_pos, length, thread);
242 static void set_property(Handle props, const char* key, const char* value, TRAPS) {
243 JavaValue r(T_OBJECT);
244 // public synchronized Object put(Object key, Object value);
245 HandleMark hm(THREAD);
246 Handle key_str = java_lang_String::create_from_platform_dependent_str(key, CHECK);
247 Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK);
248 JavaCalls::call_virtual(&r,
250 KlassHandle(THREAD, SystemDictionary::properties_klass()),
251 vmSymbolHandles::put_name(),
252 vmSymbolHandles::object_object_object_signature(),
259 #define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties));
262 JVM_ENTRY(jobject, JVM_InitProperties(JNIEnv *env, jobject properties))
263 JVMWrapper("JVM_InitProperties");
266 Handle props(THREAD, JNIHandles::resolve_non_null(properties));
268 // System property list includes both user set via -D option and
269 // jvm system specific properties.
270 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
271 PUTPROP(props, p->key(), p->value());
274 // Convert the -XX:MaxDirectMemorySize= command line flag
275 // to the sun.nio.MaxDirectMemorySize property.
276 // Do this after setting user properties to prevent people
277 // from setting the value with a -D option, as requested.
280 jio_snprintf(as_chars, sizeof(as_chars), INTX_FORMAT, MaxDirectMemorySize);
281 PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars);
284 // JVM monitoring and management support
285 // Add the sun.management.compiler property for the compiler's name
288 #if defined(_LP64) || defined(_WIN64)
289 #define CSIZE "64-Bit "
295 const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers";
297 #if defined(COMPILER1)
298 const char* compiler_name = "HotSpot " CSIZE "Client Compiler";
299 #elif defined(COMPILER2)
300 const char* compiler_name = "HotSpot " CSIZE "Server Compiler";
302 const char* compiler_name = "";
306 if (*compiler_name != '\0' &&
307 (Arguments::mode() != Arguments::_int)) {
308 PUTPROP(props, "sun.management.compiler", compiler_name);
316 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
318 extern volatile jint vm_created;
320 JVM_ENTRY_NO_ENV(void, JVM_Exit(jint code))
321 if (vm_created != 0 && (code == 0)) {
322 // The VM is about to exit. We call back into Java to check whether finalizers should be run
323 Universe::run_finalizers_on_exit();
330 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
336 JVM_LEAF(void, JVM_OnExit(void (*func)(void)))
337 register_on_exit_function(func);
341 JVM_ENTRY_NO_ENV(void, JVM_GC(void))
342 JVMWrapper("JVM_GC");
343 if (!DisableExplicitGC) {
344 Universe::heap()->collect(GCCause::_java_lang_system_gc);
349 JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void))
350 JVMWrapper("JVM_MaxObjectInspectionAge");
351 return Universe::heap()->millis_since_last_gc();
355 JVM_LEAF(void, JVM_TraceInstructions(jboolean on))
356 if (PrintJVMWarnings) warning("JVM_TraceInstructions not supported");
360 JVM_LEAF(void, JVM_TraceMethodCalls(jboolean on))
361 if (PrintJVMWarnings) warning("JVM_TraceMethodCalls not supported");
364 static inline jlong convert_size_t_to_jlong(size_t val) {
365 // In the 64-bit vm, a size_t can overflow a jlong (which is signed).
366 NOT_LP64 (return (jlong)val;)
367 LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);)
370 JVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void))
371 JVMWrapper("JVM_TotalMemory");
372 size_t n = Universe::heap()->capacity();
373 return convert_size_t_to_jlong(n);
377 JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void))
378 JVMWrapper("JVM_FreeMemory");
379 CollectedHeap* ch = Universe::heap();
380 size_t n = ch->capacity() - ch->used();
381 return convert_size_t_to_jlong(n);
385 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
386 JVMWrapper("JVM_MaxMemory");
387 size_t n = Universe::heap()->max_capacity();
388 return convert_size_t_to_jlong(n);
392 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
393 JVMWrapper("JVM_ActiveProcessorCount");
394 return os::active_processor_count();
399 // java.lang.Throwable //////////////////////////////////////////////////////
402 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
403 JVMWrapper("JVM_FillInStackTrace");
404 Handle exception(thread, JNIHandles::resolve_non_null(receiver));
405 java_lang_Throwable::fill_in_stack_trace(exception);
409 JVM_ENTRY(void, JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable))
410 JVMWrapper("JVM_PrintStackTrace");
411 // Note: This is no longer used in Merlin, but we still support it for compatibility.
412 oop exception = JNIHandles::resolve_non_null(receiver);
413 oop stream = JNIHandles::resolve_non_null(printable);
414 java_lang_Throwable::print_stack_trace(exception, stream);
418 JVM_ENTRY(jint, JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable))
419 JVMWrapper("JVM_GetStackTraceDepth");
420 oop exception = JNIHandles::resolve(throwable);
421 return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
425 JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
426 JVMWrapper("JVM_GetStackTraceElement");
427 JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
428 oop exception = JNIHandles::resolve(throwable);
429 oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
430 return JNIHandles::make_local(env, element);
434 // java.lang.Object ///////////////////////////////////////////////
437 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
438 JVMWrapper("JVM_IHashCode");
439 // as implemented in the classic virtual machine; return 0 if object is NULL
440 return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
444 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
445 JVMWrapper("JVM_MonitorWait");
446 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
447 assert(obj->is_instance() || obj->is_array(), "JVM_MonitorWait must apply to an object");
448 JavaThreadInObjectWaitState jtiows(thread, ms != 0);
449 if (JvmtiExport::should_post_monitor_wait()) {
450 JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
452 ObjectSynchronizer::wait(obj, ms, CHECK);
456 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
457 JVMWrapper("JVM_MonitorNotify");
458 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
459 assert(obj->is_instance() || obj->is_array(), "JVM_MonitorNotify must apply to an object");
460 ObjectSynchronizer::notify(obj, CHECK);
464 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
465 JVMWrapper("JVM_MonitorNotifyAll");
466 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
467 assert(obj->is_instance() || obj->is_array(), "JVM_MonitorNotifyAll must apply to an object");
468 ObjectSynchronizer::notifyall(obj, CHECK);
472 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
473 JVMWrapper("JVM_Clone");
474 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
475 const KlassHandle klass (THREAD, obj->klass());
476 JvmtiVMObjectAllocEventCollector oam;
479 // Just checking that the cloneable flag is set correct
480 if (obj->is_javaArray()) {
481 guarantee(klass->is_cloneable(), "all arrays are cloneable");
483 guarantee(obj->is_instance(), "should be instanceOop");
484 bool cloneable = klass->is_subtype_of(SystemDictionary::cloneable_klass());
485 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
489 // Check if class of obj supports the Cloneable interface.
490 // All arrays are considered to be cloneable (See JLS 20.1.5)
491 if (!klass->is_cloneable()) {
492 ResourceMark rm(THREAD);
493 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
496 // Make shallow object copy
497 const int size = obj->size();
499 if (obj->is_javaArray()) {
500 const int length = ((arrayOop)obj())->length();
501 new_obj = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
503 new_obj = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
505 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
506 // is modifying a reference field in the clonee, a non-oop-atomic copy might
507 // be suspended in the middle of copying the pointer and end up with parts
508 // of two different pointers in the field. Subsequent dereferences will crash.
509 // 4846409: an oop-copy of objects with long or double fields or arrays of same
510 // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
511 // of oops. We know objects are aligned on a minimum of an jlong boundary.
512 // The same is true of StubRoutines::object_copy and the various oop_copy
513 // variants, and of the code generated by the inline_native_clone intrinsic.
514 assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
515 Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj,
516 (size_t)align_object_size(size) / HeapWordsPerLong);
518 new_obj->init_mark();
520 // Store check (mark entire object and let gc sort it out)
521 BarrierSet* bs = Universe::heap()->barrier_set();
522 assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
523 bs->write_region(MemRegion((HeapWord*)new_obj, size));
525 // Caution: this involves a java upcall, so the clone should be
526 // "gc-robust" by this stage.
527 if (klass->has_finalizer()) {
528 assert(obj->is_instance(), "should be instanceOop");
529 new_obj = instanceKlass::register_finalizer(instanceOop(new_obj), CHECK_NULL);
532 return JNIHandles::make_local(env, oop(new_obj));
535 // java.lang.Compiler ////////////////////////////////////////////////////
537 // The initial cuts of the HotSpot VM will not support JITs, and all existing
538 // JITs would need extensive changes to work with HotSpot. The JIT-related JVM
539 // functions are all silently ignored unless JVM warnings are printed.
541 JVM_LEAF(void, JVM_InitializeCompiler (JNIEnv *env, jclass compCls))
542 if (PrintJVMWarnings) warning("JVM_InitializeCompiler not supported");
546 JVM_LEAF(jboolean, JVM_IsSilentCompiler(JNIEnv *env, jclass compCls))
547 if (PrintJVMWarnings) warning("JVM_IsSilentCompiler not supported");
552 JVM_LEAF(jboolean, JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls))
553 if (PrintJVMWarnings) warning("JVM_CompileClass not supported");
558 JVM_LEAF(jboolean, JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname))
559 if (PrintJVMWarnings) warning("JVM_CompileClasses not supported");
564 JVM_LEAF(jobject, JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg))
565 if (PrintJVMWarnings) warning("JVM_CompilerCommand not supported");
570 JVM_LEAF(void, JVM_EnableCompiler(JNIEnv *env, jclass compCls))
571 if (PrintJVMWarnings) warning("JVM_EnableCompiler not supported");
575 JVM_LEAF(void, JVM_DisableCompiler(JNIEnv *env, jclass compCls))
576 if (PrintJVMWarnings) warning("JVM_DisableCompiler not supported");
581 // Error message support //////////////////////////////////////////////////////
583 JVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len))
584 JVMWrapper("JVM_GetLastErrorString");
585 return hpi::lasterror(buf, len);
589 // java.io.File ///////////////////////////////////////////////////////////////
591 JVM_LEAF(char*, JVM_NativePath(char* path))
592 JVMWrapper2("JVM_NativePath (%s)", path);
593 return hpi::native_path(path);
597 // Misc. class handling ///////////////////////////////////////////////////////////
600 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
601 JVMWrapper("JVM_GetCallerClass");
602 klassOop k = thread->security_get_caller_class(depth);
603 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
607 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
608 JVMWrapper("JVM_FindPrimitiveClass");
610 BasicType t = name2type(utf);
611 if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
612 mirror = Universe::java_mirror(t);
614 if (mirror == NULL) {
615 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
617 return (jclass) JNIHandles::make_local(env, mirror);
622 JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls))
623 JVMWrapper("JVM_ResolveClass");
624 if (PrintJVMWarnings) warning("JVM_ResolveClass not implemented");
627 // Rationale behind JVM_FindClassFromBootLoader
628 // a> JVM_FindClassFromClassLoader was never exported in the export tables.
629 // b> because of (a) java.dll has a direct dependecy on the unexported
630 // private symbol "_JVM_FindClassFromClassLoader@20".
631 // c> the launcher cannot use the private symbol as it dynamically opens
632 // the entry point, so if something changes, the launcher will fail
633 // unexpectedly at runtime, it is safest for the launcher to dlopen a
634 // stable exported interface.
635 // d> re-exporting JVM_FindClassFromClassLoader as public, will cause its
636 // signature to change from _JVM_FindClassFromClassLoader@20 to
637 // JVM_FindClassFromClassLoader and will not be backward compatible
639 // Thus a public/stable exported entry point is the right solution,
640 // public here means public in linker semantics, and is exported only
641 // to the JDK, and is not intended to be a public API.
643 JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
645 jboolean throwError))
646 JVMWrapper3("JVM_FindClassFromBootLoader %s throw %s", name,
647 throwError ? "error" : "exception");
648 return JVM_FindClassFromClassLoader(env, name, JNI_FALSE,
649 (jobject)NULL, throwError);
652 JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name,
653 jboolean init, jobject loader,
654 jboolean throwError))
655 JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name,
656 throwError ? "error" : "exception");
657 // Java libraries should ensure that name is never null...
658 if (name == NULL || (int)strlen(name) > symbolOopDesc::max_length()) {
659 // It's impossible to create this class; the name cannot fit
660 // into the constant pool.
662 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
664 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
667 symbolHandle h_name = oopFactory::new_symbol_handle(name, CHECK_NULL);
668 Handle h_loader(THREAD, JNIHandles::resolve(loader));
669 jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
670 Handle(), throwError, thread);
672 if (TraceClassResolution && result != NULL) {
673 trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result)));
680 JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name,
681 jboolean init, jclass from))
682 JVMWrapper2("JVM_FindClassFromClass %s", name);
683 if (name == NULL || (int)strlen(name) > symbolOopDesc::max_length()) {
684 // It's impossible to create this class; the name cannot fit
685 // into the constant pool.
686 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
688 symbolHandle h_name = oopFactory::new_symbol_handle(name, CHECK_NULL);
689 oop from_class_oop = JNIHandles::resolve(from);
690 klassOop from_class = (from_class_oop == NULL)
692 : java_lang_Class::as_klassOop(from_class_oop);
693 oop class_loader = NULL;
694 oop protection_domain = NULL;
695 if (from_class != NULL) {
696 class_loader = Klass::cast(from_class)->class_loader();
697 protection_domain = Klass::cast(from_class)->protection_domain();
699 Handle h_loader(THREAD, class_loader);
700 Handle h_prot (THREAD, protection_domain);
701 jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
702 h_prot, true, thread);
704 if (TraceClassResolution && result != NULL) {
705 // this function is generally only used for class loading during verification.
707 oop from_mirror = JNIHandles::resolve_non_null(from);
708 klassOop from_class = java_lang_Class::as_klassOop(from_mirror);
709 const char * from_name = Klass::cast(from_class)->external_name();
711 oop mirror = JNIHandles::resolve_non_null(result);
712 klassOop to_class = java_lang_Class::as_klassOop(mirror);
713 const char * to = Klass::cast(to_class)->external_name();
714 tty->print("RESOLVE %s %s (verification)\n", from_name, to);
720 static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) {
721 if (loader.is_null()) {
725 // check whether the current caller thread holds the lock or not.
726 // If not, increment the corresponding counter
727 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader) !=
728 ObjectSynchronizer::owner_self) {
733 // common code for JVM_DefineClass() and JVM_DefineClassWithSource()
734 static jclass jvm_define_class_common(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source, TRAPS) {
736 // Since exceptions can be thrown, class initialization can take place
737 // if name is NULL no check for class name in .class stream has to be made.
738 symbolHandle class_name;
740 const int str_len = (int)strlen(name);
741 if (str_len > symbolOopDesc::max_length()) {
742 // It's impossible to create this class; the name cannot fit
743 // into the constant pool.
744 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
746 class_name = oopFactory::new_symbol_handle(name, str_len, CHECK_NULL);
749 ResourceMark rm(THREAD);
750 ClassFileStream st((u1*) buf, len, (char *)source);
751 Handle class_loader (THREAD, JNIHandles::resolve(loader));
753 is_lock_held_by_thread(class_loader,
754 ClassLoader::sync_JVMDefineClassLockFreeCounter(),
757 Handle protection_domain (THREAD, JNIHandles::resolve(pd));
758 klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
759 protection_domain, &st,
762 if (TraceClassResolution && k != NULL) {
763 trace_class_resolution(k);
766 return (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
770 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
771 JVMWrapper2("JVM_DefineClass %s", name);
773 return jvm_define_class_common(env, name, loader, buf, len, pd, "__JVM_DefineClass__", THREAD);
777 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
778 JVMWrapper2("JVM_DefineClassWithSource %s", name);
780 return jvm_define_class_common(env, name, loader, buf, len, pd, source, THREAD);
784 JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name))
785 JVMWrapper("JVM_FindLoadedClass");
786 ResourceMark rm(THREAD);
788 Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
789 Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
791 const char* str = java_lang_String::as_utf8_string(string());
792 // Sanity check, don't expect null
793 if (str == NULL) return NULL;
795 const int str_len = (int)strlen(str);
796 if (str_len > symbolOopDesc::max_length()) {
797 // It's impossible to create this class; the name cannot fit
798 // into the constant pool.
801 symbolHandle klass_name = oopFactory::new_symbol_handle(str, str_len,CHECK_NULL);
804 // The Java level wrapper will perform the necessary security check allowing
805 // us to pass the NULL as the initiating class loader.
806 Handle h_loader(THREAD, JNIHandles::resolve(loader));
808 is_lock_held_by_thread(h_loader,
809 ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
813 klassOop k = SystemDictionary::find_instance_or_array_klass(klass_name,
818 return (k == NULL) ? NULL :
819 (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
823 // Reflection support //////////////////////////////////////////////////////////////////////////////
825 JVM_ENTRY(jstring, JVM_GetClassName(JNIEnv *env, jclass cls))
826 assert (cls != NULL, "illegal class");
827 JVMWrapper("JVM_GetClassName");
828 JvmtiVMObjectAllocEventCollector oam;
829 ResourceMark rm(THREAD);
831 if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
832 name = type2name(java_lang_Class::primitive_type(JNIHandles::resolve(cls)));
834 // Consider caching interned string in Klass
835 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
836 assert(k->is_klass(), "just checking");
837 name = Klass::cast(k)->external_name();
839 oop result = StringTable::intern((char*) name, CHECK_NULL);
840 return (jstring) JNIHandles::make_local(env, result);
844 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
845 JVMWrapper("JVM_GetClassInterfaces");
846 JvmtiVMObjectAllocEventCollector oam;
847 oop mirror = JNIHandles::resolve_non_null(cls);
849 // Special handling for primitive objects
850 if (java_lang_Class::is_primitive(mirror)) {
851 // Primitive objects does not have any interfaces
852 objArrayOop r = oopFactory::new_objArray(SystemDictionary::class_klass(), 0, CHECK_NULL);
853 return (jobjectArray) JNIHandles::make_local(env, r);
856 KlassHandle klass(thread, java_lang_Class::as_klassOop(mirror));
857 // Figure size of result array
859 if (klass->oop_is_instance()) {
860 size = instanceKlass::cast(klass())->local_interfaces()->length();
862 assert(klass->oop_is_objArray() || klass->oop_is_typeArray(), "Illegal mirror klass");
866 // Allocate result array
867 objArrayOop r = oopFactory::new_objArray(SystemDictionary::class_klass(), size, CHECK_NULL);
868 objArrayHandle result (THREAD, r);
870 if (klass->oop_is_instance()) {
871 // Regular instance klass, fill in all local interfaces
872 for (int index = 0; index < size; index++) {
873 klassOop k = klassOop(instanceKlass::cast(klass())->local_interfaces()->obj_at(index));
874 result->obj_at_put(index, Klass::cast(k)->java_mirror());
877 // All arrays implement java.lang.Cloneable and java.io.Serializable
878 result->obj_at_put(0, Klass::cast(SystemDictionary::cloneable_klass())->java_mirror());
879 result->obj_at_put(1, Klass::cast(SystemDictionary::serializable_klass())->java_mirror());
881 return (jobjectArray) JNIHandles::make_local(env, result());
885 JVM_ENTRY(jobject, JVM_GetClassLoader(JNIEnv *env, jclass cls))
886 JVMWrapper("JVM_GetClassLoader");
887 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
890 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
891 oop loader = Klass::cast(k)->class_loader();
892 return JNIHandles::make_local(env, loader);
896 JVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
897 JVMWrapper("JVM_IsInterface");
898 oop mirror = JNIHandles::resolve_non_null(cls);
899 if (java_lang_Class::is_primitive(mirror)) {
902 klassOop k = java_lang_Class::as_klassOop(mirror);
903 jboolean result = Klass::cast(k)->is_interface();
904 assert(!result || Klass::cast(k)->oop_is_instance(),
905 "all interfaces are instance types");
906 // The compiler intrinsic for isInterface tests the
907 // Klass::_access_flags bits in the same way.
912 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
913 JVMWrapper("JVM_GetClassSigners");
914 JvmtiVMObjectAllocEventCollector oam;
915 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
916 // There are no signers for primitive types
920 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
921 objArrayOop signers = NULL;
922 if (Klass::cast(k)->oop_is_instance()) {
923 signers = instanceKlass::cast(k)->signers();
926 // If there are no signers set in the class, or if the class
927 // is an array, return NULL.
928 if (signers == NULL) return NULL;
930 // copy of the signers array
931 klassOop element = objArrayKlass::cast(signers->klass())->element_klass();
932 objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
933 for (int index = 0; index < signers->length(); index++) {
934 signers_copy->obj_at_put(index, signers->obj_at(index));
938 return (jobjectArray) JNIHandles::make_local(env, signers_copy);
942 JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers))
943 JVMWrapper("JVM_SetClassSigners");
944 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
945 // This call is ignored for primitive types and arrays.
946 // Signers are only set once, ClassLoader.java, and thus shouldn't
947 // be called with an array. Only the bootstrap loader creates arrays.
948 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
949 if (Klass::cast(k)->oop_is_instance()) {
950 instanceKlass::cast(k)->set_signers(objArrayOop(JNIHandles::resolve(signers)));
956 JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls))
957 JVMWrapper("JVM_GetProtectionDomain");
958 if (JNIHandles::resolve(cls) == NULL) {
959 THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
962 if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
963 // Primitive types does not have a protection domain.
967 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
968 return (jobject) JNIHandles::make_local(env, Klass::cast(k)->protection_domain());
972 // Obsolete since 1.2 (Class.setProtectionDomain removed), although
973 // still defined in core libraries as of 1.5.
974 JVM_ENTRY(void, JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain))
975 JVMWrapper("JVM_SetProtectionDomain");
976 if (JNIHandles::resolve(cls) == NULL) {
977 THROW(vmSymbols::java_lang_NullPointerException());
979 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
980 // Call is ignored for primitive types
981 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
983 // cls won't be an array, as this called only from ClassLoader.defineClass
984 if (Klass::cast(k)->oop_is_instance()) {
985 oop pd = JNIHandles::resolve(protection_domain);
986 assert(pd == NULL || pd->is_oop(), "just checking");
987 instanceKlass::cast(k)->set_protection_domain(pd);
993 JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))
994 JVMWrapper("JVM_DoPrivileged");
996 if (action == NULL) {
997 THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action");
1000 // Stack allocated list of privileged stack elements
1001 PrivilegedElement pi;
1003 // Check that action object understands "Object run()"
1004 Handle object (THREAD, JNIHandles::resolve(action));
1007 methodOop m_oop = Klass::cast(object->klass())->uncached_lookup_method(
1008 vmSymbols::run_method_name(),
1009 vmSymbols::void_object_signature());
1010 methodHandle m (THREAD, m_oop);
1011 if (m.is_null() || !m->is_method() || !methodOop(m())->is_public() || methodOop(m())->is_static()) {
1012 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
1015 // Compute the frame initiating the do privileged operation and setup the privileged stack
1016 vframeStream vfst(thread);
1017 vfst.security_get_caller_frame(1);
1019 if (!vfst.at_end()) {
1020 pi.initialize(&vfst, JNIHandles::resolve(context), thread->privileged_stack_top(), CHECK_NULL);
1021 thread->set_privileged_stack_top(&pi);
1025 // invoke the Object run() in the action object. We cannot use call_interface here, since the static type
1026 // is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction
1027 Handle pending_exception;
1028 JavaValue result(T_OBJECT);
1029 JavaCallArguments args(object);
1030 JavaCalls::call(&result, m, &args, THREAD);
1032 // done with action, remove ourselves from the list
1033 if (!vfst.at_end()) {
1034 assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element");
1035 thread->set_privileged_stack_top(thread->privileged_stack_top()->next());
1038 if (HAS_PENDING_EXCEPTION) {
1039 pending_exception = Handle(THREAD, PENDING_EXCEPTION);
1040 CLEAR_PENDING_EXCEPTION;
1042 if ( pending_exception->is_a(SystemDictionary::exception_klass()) &&
1043 !pending_exception->is_a(SystemDictionary::runtime_exception_klass())) {
1044 // Throw a java.security.PrivilegedActionException(Exception e) exception
1045 JavaCallArguments args(pending_exception);
1046 THROW_ARG_0(vmSymbolHandles::java_security_PrivilegedActionException(),
1047 vmSymbolHandles::exception_void_signature(),
1052 if (pending_exception.not_null()) THROW_OOP_0(pending_exception());
1053 return JNIHandles::make_local(env, (oop) result.get_jobject());
1057 // Returns the inherited_access_control_context field of the running thread.
1058 JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls))
1059 JVMWrapper("JVM_GetInheritedAccessControlContext");
1060 oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj());
1061 return JNIHandles::make_local(env, result);
1064 class RegisterArrayForGC {
1066 JavaThread *_thread;
1068 RegisterArrayForGC(JavaThread *thread, GrowableArray<oop>* array) {
1070 _thread->register_array_for_gc(array);
1073 ~RegisterArrayForGC() {
1074 _thread->register_array_for_gc(NULL);
1079 JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls))
1080 JVMWrapper("JVM_GetStackAccessControlContext");
1081 if (!UsePrivilegedStack) return NULL;
1083 ResourceMark rm(THREAD);
1084 GrowableArray<oop>* local_array = new GrowableArray<oop>(12);
1085 JvmtiVMObjectAllocEventCollector oam;
1087 // count the protection domains on the execution stack. We collapse
1088 // duplicate consecutive protection domains into a single one, as
1089 // well as stopping when we hit a privileged frame.
1091 // Use vframeStream to iterate through Java frames
1092 vframeStream vfst(thread);
1094 oop previous_protection_domain = NULL;
1095 Handle privileged_context(thread, NULL);
1096 bool is_privileged = false;
1097 oop protection_domain = NULL;
1099 for(; !vfst.at_end(); vfst.next()) {
1100 // get method of frame
1101 methodOop method = vfst.method();
1102 intptr_t* frame_id = vfst.frame_id();
1104 // check the privileged frames to see if we have a match
1105 if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) {
1106 // this frame is privileged
1107 is_privileged = true;
1108 privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
1109 protection_domain = thread->privileged_stack_top()->protection_domain();
1111 protection_domain = instanceKlass::cast(method->method_holder())->protection_domain();
1114 if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
1115 local_array->push(protection_domain);
1116 previous_protection_domain = protection_domain;
1119 if (is_privileged) break;
1123 // either all the domains on the stack were system domains, or
1124 // we had a privileged system domain
1125 if (local_array->is_empty()) {
1126 if (is_privileged && privileged_context.is_null()) return NULL;
1128 oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
1129 return JNIHandles::make_local(env, result);
1132 // the resource area must be registered in case of a gc
1133 RegisterArrayForGC ragc(thread, local_array);
1134 objArrayOop context = oopFactory::new_objArray(SystemDictionary::protectionDomain_klass(),
1135 local_array->length(), CHECK_NULL);
1136 objArrayHandle h_context(thread, context);
1137 for (int index = 0; index < local_array->length(); index++) {
1138 h_context->obj_at_put(index, local_array->at(index));
1141 oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
1143 return JNIHandles::make_local(env, result);
1147 JVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
1148 JVMWrapper("JVM_IsArrayClass");
1149 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
1150 return (k != NULL) && Klass::cast(k)->oop_is_javaArray() ? true : false;
1154 JVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
1155 JVMWrapper("JVM_IsPrimitiveClass");
1156 oop mirror = JNIHandles::resolve_non_null(cls);
1157 return (jboolean) java_lang_Class::is_primitive(mirror);
1161 JVM_ENTRY(jclass, JVM_GetComponentType(JNIEnv *env, jclass cls))
1162 JVMWrapper("JVM_GetComponentType");
1163 oop mirror = JNIHandles::resolve_non_null(cls);
1164 oop result = Reflection::array_component_type(mirror, CHECK_NULL);
1165 return (jclass) JNIHandles::make_local(env, result);
1169 JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls))
1170 JVMWrapper("JVM_GetClassModifiers");
1171 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
1173 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
1176 Klass* k = Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)));
1177 debug_only(int computed_modifiers = k->compute_modifier_flags(CHECK_0));
1178 assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK");
1179 return k->modifier_flags();
1183 // Inner class reflection ///////////////////////////////////////////////////////////////////////////////
1185 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass))
1186 const int inner_class_info_index = 0;
1187 const int outer_class_info_index = 1;
1189 JvmtiVMObjectAllocEventCollector oam;
1190 // ofClass is a reference to a java_lang_Class object. The mirror object
1191 // of an instanceKlass
1193 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
1194 ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) {
1195 oop result = oopFactory::new_objArray(SystemDictionary::class_klass(), 0, CHECK_NULL);
1196 return (jobjectArray)JNIHandles::make_local(env, result);
1199 instanceKlassHandle k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
1201 if (k->inner_classes()->length() == 0) {
1202 // Neither an inner nor outer class
1203 oop result = oopFactory::new_objArray(SystemDictionary::class_klass(), 0, CHECK_NULL);
1204 return (jobjectArray)JNIHandles::make_local(env, result);
1207 // find inner class info
1208 typeArrayHandle icls(thread, k->inner_classes());
1209 constantPoolHandle cp(thread, k->constants());
1210 int length = icls->length();
1212 // Allocate temp. result array
1213 objArrayOop r = oopFactory::new_objArray(SystemDictionary::class_klass(), length/4, CHECK_NULL);
1214 objArrayHandle result (THREAD, r);
1217 for(int i = 0; i < length; i += 4) {
1218 int ioff = icls->ushort_at(i + inner_class_info_index);
1219 int ooff = icls->ushort_at(i + outer_class_info_index);
1221 if (ioff != 0 && ooff != 0) {
1222 // Check to see if the name matches the class we're looking for
1223 // before attempting to find the class.
1224 if (cp->klass_name_at_matches(k, ooff)) {
1225 klassOop outer_klass = cp->klass_at(ooff, CHECK_NULL);
1226 if (outer_klass == k()) {
1227 klassOop ik = cp->klass_at(ioff, CHECK_NULL);
1228 instanceKlassHandle inner_klass (THREAD, ik);
1230 // Throws an exception if outer klass has not declared k as
1232 Reflection::check_for_inner_class(k, inner_klass, CHECK_NULL);
1234 result->obj_at_put(members, inner_klass->java_mirror());
1241 if (members != length) {
1242 // Return array of right length
1243 objArrayOop res = oopFactory::new_objArray(SystemDictionary::class_klass(), members, CHECK_NULL);
1244 for(int i = 0; i < members; i++) {
1245 res->obj_at_put(i, result->obj_at(i));
1247 return (jobjectArray)JNIHandles::make_local(env, res);
1250 return (jobjectArray)JNIHandles::make_local(env, result());
1254 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
1255 const int inner_class_info_index = 0;
1256 const int outer_class_info_index = 1;
1258 // ofClass is a reference to a java_lang_Class object.
1259 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
1260 ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) {
1264 instanceKlassHandle k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
1266 if (k->inner_classes()->length() == 0) {
1267 // No inner class info => no declaring class
1271 typeArrayHandle i_icls(thread, k->inner_classes());
1272 constantPoolHandle i_cp(thread, k->constants());
1273 int i_length = i_icls->length();
1277 instanceKlassHandle outer_klass;
1279 // Find inner_klass attribute
1280 for(int i = 0; i < i_length && !found; i+= 4) {
1281 int ioff = i_icls->ushort_at(i + inner_class_info_index);
1282 int ooff = i_icls->ushort_at(i + outer_class_info_index);
1284 if (ioff != 0 && ooff != 0) {
1285 // Check to see if the name matches the class we're looking for
1286 // before attempting to find the class.
1287 if (i_cp->klass_name_at_matches(k, ioff)) {
1288 klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL);
1289 if (k() == inner_klass) {
1291 ok = i_cp->klass_at(ooff, CHECK_NULL);
1292 outer_klass = instanceKlassHandle(thread, ok);
1298 // If no inner class attribute found for this class.
1299 if (!found) return NULL;
1301 // Throws an exception if outer klass has not declared k as an inner klass
1302 Reflection::check_for_inner_class(outer_klass, k, CHECK_NULL);
1304 return (jclass)JNIHandles::make_local(env, outer_klass->java_mirror());
1308 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls))
1309 assert (cls != NULL, "illegal class");
1310 JVMWrapper("JVM_GetClassSignature");
1311 JvmtiVMObjectAllocEventCollector oam;
1312 ResourceMark rm(THREAD);
1313 // Return null for arrays and primatives
1314 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
1315 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
1316 if (Klass::cast(k)->oop_is_instance()) {
1317 symbolHandle sym = symbolHandle(THREAD, instanceKlass::cast(k)->generic_signature());
1318 if (sym.is_null()) return NULL;
1319 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
1320 return (jstring) JNIHandles::make_local(env, str());
1327 JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
1328 assert (cls != NULL, "illegal class");
1329 JVMWrapper("JVM_GetClassAnnotations");
1330 ResourceMark rm(THREAD);
1331 // Return null for arrays and primitives
1332 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
1333 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
1334 if (Klass::cast(k)->oop_is_instance()) {
1335 return (jbyteArray) JNIHandles::make_local(env,
1336 instanceKlass::cast(k)->class_annotations());
1343 JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field))
1344 assert(field != NULL, "illegal field");
1345 JVMWrapper("JVM_GetFieldAnnotations");
1347 // some of this code was adapted from from jni_FromReflectedField
1349 // field is a handle to a java.lang.reflect.Field object
1350 oop reflected = JNIHandles::resolve_non_null(field);
1351 oop mirror = java_lang_reflect_Field::clazz(reflected);
1352 klassOop k = java_lang_Class::as_klassOop(mirror);
1353 int slot = java_lang_reflect_Field::slot(reflected);
1354 int modifiers = java_lang_reflect_Field::modifiers(reflected);
1357 KlassHandle kh(THREAD, k);
1358 intptr_t offset = instanceKlass::cast(kh())->offset_from_fields(slot);
1360 if (modifiers & JVM_ACC_STATIC) {
1361 // for static fields we only look in the current class
1362 if (!instanceKlass::cast(kh())->find_local_field_from_offset(offset,
1364 assert(false, "cannot find static field");
1365 return NULL; // robustness
1368 // for instance fields we start with the current class and work
1369 // our way up through the superclass chain
1370 if (!instanceKlass::cast(kh())->find_field_from_offset(offset, false,
1372 assert(false, "cannot find instance field");
1373 return NULL; // robustness
1377 return (jbyteArray) JNIHandles::make_local(env, fd.annotations());
1381 static methodOop jvm_get_method_common(jobject method, TRAPS) {
1382 // some of this code was adapted from from jni_FromReflectedMethod
1384 oop reflected = JNIHandles::resolve_non_null(method);
1388 if (reflected->klass() == SystemDictionary::reflect_constructor_klass()) {
1389 mirror = java_lang_reflect_Constructor::clazz(reflected);
1390 slot = java_lang_reflect_Constructor::slot(reflected);
1392 assert(reflected->klass() == SystemDictionary::reflect_method_klass(),
1394 mirror = java_lang_reflect_Method::clazz(reflected);
1395 slot = java_lang_reflect_Method::slot(reflected);
1397 klassOop k = java_lang_Class::as_klassOop(mirror);
1399 KlassHandle kh(THREAD, k);
1400 methodOop m = instanceKlass::cast(kh())->method_with_idnum(slot);
1402 assert(false, "cannot find method");
1403 return NULL; // robustness
1410 JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method))
1411 JVMWrapper("JVM_GetMethodAnnotations");
1413 // method is a handle to a java.lang.reflect.Method object
1414 methodOop m = jvm_get_method_common(method, CHECK_NULL);
1415 return (jbyteArray) JNIHandles::make_local(env, m->annotations());
1419 JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method))
1420 JVMWrapper("JVM_GetMethodDefaultAnnotationValue");
1422 // method is a handle to a java.lang.reflect.Method object
1423 methodOop m = jvm_get_method_common(method, CHECK_NULL);
1424 return (jbyteArray) JNIHandles::make_local(env, m->annotation_default());
1428 JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method))
1429 JVMWrapper("JVM_GetMethodParameterAnnotations");
1431 // method is a handle to a java.lang.reflect.Method object
1432 methodOop m = jvm_get_method_common(method, CHECK_NULL);
1433 return (jbyteArray) JNIHandles::make_local(env, m->parameter_annotations());
1437 // New (JDK 1.4) reflection implementation /////////////////////////////////////
1439 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1441 JVMWrapper("JVM_GetClassDeclaredFields");
1442 JvmtiVMObjectAllocEventCollector oam;
1444 // Exclude primitive types and array types
1445 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
1446 Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
1447 // Return empty array
1448 oop res = oopFactory::new_objArray(SystemDictionary::reflect_field_klass(), 0, CHECK_NULL);
1449 return (jobjectArray) JNIHandles::make_local(env, res);
1452 instanceKlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
1453 constantPoolHandle cp(THREAD, k->constants());
1455 // Ensure class is linked
1456 k->link_class(CHECK_NULL);
1458 typeArrayHandle fields(THREAD, k->fields());
1459 int fields_len = fields->length();
1461 // 4496456 We need to filter out java.lang.Throwable.backtrace
1462 bool skip_backtrace = false;
1469 for (int i = 0, j = 0; i < fields_len; i += instanceKlass::next_offset, j++) {
1470 int mods = fields->ushort_at(i + instanceKlass::access_flags_offset) & JVM_RECOGNIZED_FIELD_MODIFIERS;
1471 if (mods & JVM_ACC_PUBLIC) ++num_fields;
1474 num_fields = fields_len / instanceKlass::next_offset;
1476 if (k() == SystemDictionary::throwable_klass()) {
1478 skip_backtrace = true;
1482 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_field_klass(), num_fields, CHECK_NULL);
1483 objArrayHandle result (THREAD, r);
1487 for (int i = 0; i < fields_len; i += instanceKlass::next_offset) {
1488 if (skip_backtrace) {
1489 // 4496456 skip java.lang.Throwable.backtrace
1490 int offset = k->offset_from_fields(i);
1491 if (offset == java_lang_Throwable::get_backtrace_offset()) continue;
1494 int mods = fields->ushort_at(i + instanceKlass::access_flags_offset) & JVM_RECOGNIZED_FIELD_MODIFIERS;
1495 if (!publicOnly || (mods & JVM_ACC_PUBLIC)) {
1496 fd.initialize(k(), i);
1497 oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL);
1498 result->obj_at_put(out_idx, field);
1502 assert(out_idx == num_fields, "just checking");
1503 return (jobjectArray) JNIHandles::make_local(env, result());
1507 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1509 JVMWrapper("JVM_GetClassDeclaredMethods");
1510 JvmtiVMObjectAllocEventCollector oam;
1512 // Exclude primitive types and array types
1513 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1514 || Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
1515 // Return empty array
1516 oop res = oopFactory::new_objArray(SystemDictionary::reflect_method_klass(), 0, CHECK_NULL);
1517 return (jobjectArray) JNIHandles::make_local(env, res);
1520 instanceKlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
1522 // Ensure class is linked
1523 k->link_class(CHECK_NULL);
1525 objArrayHandle methods (THREAD, k->methods());
1526 int methods_length = methods->length();
1527 int num_methods = 0;
1530 for (i = 0; i < methods_length; i++) {
1531 methodHandle method(THREAD, (methodOop) methods->obj_at(i));
1532 if (!method->is_initializer()) {
1533 if (!publicOnly || method->is_public()) {
1540 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_method_klass(), num_methods, CHECK_NULL);
1541 objArrayHandle result (THREAD, r);
1544 for (i = 0; i < methods_length; i++) {
1545 methodHandle method(THREAD, (methodOop) methods->obj_at(i));
1546 if (!method->is_initializer()) {
1547 if (!publicOnly || method->is_public()) {
1548 oop m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL);
1549 result->obj_at_put(out_idx, m);
1554 assert(out_idx == num_methods, "just checking");
1555 return (jobjectArray) JNIHandles::make_local(env, result());
1559 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1561 JVMWrapper("JVM_GetClassDeclaredConstructors");
1562 JvmtiVMObjectAllocEventCollector oam;
1564 // Exclude primitive types and array types
1565 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1566 || Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
1567 // Return empty array
1568 oop res = oopFactory::new_objArray(SystemDictionary::reflect_constructor_klass(), 0 , CHECK_NULL);
1569 return (jobjectArray) JNIHandles::make_local(env, res);
1572 instanceKlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
1574 // Ensure class is linked
1575 k->link_class(CHECK_NULL);
1577 objArrayHandle methods (THREAD, k->methods());
1578 int methods_length = methods->length();
1579 int num_constructors = 0;
1582 for (i = 0; i < methods_length; i++) {
1583 methodHandle method(THREAD, (methodOop) methods->obj_at(i));
1584 if (method->is_initializer() && !method->is_static()) {
1585 if (!publicOnly || method->is_public()) {
1592 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_constructor_klass(), num_constructors, CHECK_NULL);
1593 objArrayHandle result(THREAD, r);
1596 for (i = 0; i < methods_length; i++) {
1597 methodHandle method(THREAD, (methodOop) methods->obj_at(i));
1598 if (method->is_initializer() && !method->is_static()) {
1599 if (!publicOnly || method->is_public()) {
1600 oop m = Reflection::new_constructor(method, CHECK_NULL);
1601 result->obj_at_put(out_idx, m);
1606 assert(out_idx == num_constructors, "just checking");
1607 return (jobjectArray) JNIHandles::make_local(env, result());
1611 JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls))
1613 JVMWrapper("JVM_GetClassAccessFlags");
1614 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
1616 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
1619 Klass* k = Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)));
1620 return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS;
1625 // Constant pool access //////////////////////////////////////////////////////////
1627 JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls))
1629 JVMWrapper("JVM_GetClassConstantPool");
1630 JvmtiVMObjectAllocEventCollector oam;
1632 // Return null for primitives and arrays
1633 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
1634 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
1635 if (Klass::cast(k)->oop_is_instance()) {
1636 instanceKlassHandle k_h(THREAD, k);
1637 Handle jcp = sun_reflect_ConstantPool::create(CHECK_NULL);
1638 sun_reflect_ConstantPool::set_cp_oop(jcp(), k_h->constants());
1639 return JNIHandles::make_local(jcp());
1647 JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool))
1649 JVMWrapper("JVM_ConstantPoolGetSize");
1650 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1651 return cp->length();
1656 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
1657 if (!cp->is_within_bounds(index)) {
1658 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
1663 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1665 JVMWrapper("JVM_ConstantPoolGetClassAt");
1666 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1667 bounds_check(cp, index, CHECK_NULL);
1668 constantTag tag = cp->tag_at(index);
1669 if (!tag.is_klass() && !tag.is_unresolved_klass()) {
1670 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1672 klassOop k = cp->klass_at(index, CHECK_NULL);
1673 return (jclass) JNIHandles::make_local(k->klass_part()->java_mirror());
1678 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1680 JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
1681 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1682 bounds_check(cp, index, CHECK_NULL);
1683 constantTag tag = cp->tag_at(index);
1684 if (!tag.is_klass() && !tag.is_unresolved_klass()) {
1685 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1687 klassOop k = constantPoolOopDesc::klass_at_if_loaded(cp, index);
1688 if (k == NULL) return NULL;
1689 return (jclass) JNIHandles::make_local(k->klass_part()->java_mirror());
1693 static jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
1694 constantTag tag = cp->tag_at(index);
1695 if (!tag.is_method() && !tag.is_interface_method()) {
1696 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1698 int klass_ref = cp->uncached_klass_ref_index_at(index);
1700 if (force_resolution) {
1701 k_o = cp->klass_at(klass_ref, CHECK_NULL);
1703 k_o = constantPoolOopDesc::klass_at_if_loaded(cp, klass_ref);
1704 if (k_o == NULL) return NULL;
1706 instanceKlassHandle k(THREAD, k_o);
1707 symbolOop name = cp->uncached_name_ref_at(index);
1708 symbolOop sig = cp->uncached_signature_ref_at(index);
1709 methodHandle m (THREAD, k->find_method(name, sig));
1711 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1714 if (!m->is_initializer() || m->is_static()) {
1715 method = Reflection::new_method(m, true, true, CHECK_NULL);
1717 method = Reflection::new_constructor(m, CHECK_NULL);
1719 return JNIHandles::make_local(method);
1722 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1724 JVMWrapper("JVM_ConstantPoolGetMethodAt");
1725 JvmtiVMObjectAllocEventCollector oam;
1726 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1727 bounds_check(cp, index, CHECK_NULL);
1728 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
1733 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1735 JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded");
1736 JvmtiVMObjectAllocEventCollector oam;
1737 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1738 bounds_check(cp, index, CHECK_NULL);
1739 jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);
1744 static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
1745 constantTag tag = cp->tag_at(index);
1746 if (!tag.is_field()) {
1747 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1749 int klass_ref = cp->uncached_klass_ref_index_at(index);
1751 if (force_resolution) {
1752 k_o = cp->klass_at(klass_ref, CHECK_NULL);
1754 k_o = constantPoolOopDesc::klass_at_if_loaded(cp, klass_ref);
1755 if (k_o == NULL) return NULL;
1757 instanceKlassHandle k(THREAD, k_o);
1758 symbolOop name = cp->uncached_name_ref_at(index);
1759 symbolOop sig = cp->uncached_signature_ref_at(index);
1761 klassOop target_klass = k->find_field(name, sig, &fd);
1762 if (target_klass == NULL) {
1763 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class");
1765 oop field = Reflection::new_field(&fd, true, CHECK_NULL);
1766 return JNIHandles::make_local(field);
1769 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1771 JVMWrapper("JVM_ConstantPoolGetFieldAt");
1772 JvmtiVMObjectAllocEventCollector oam;
1773 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1774 bounds_check(cp, index, CHECK_NULL);
1775 jobject res = get_field_at_helper(cp, index, true, CHECK_NULL);
1780 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1782 JVMWrapper("JVM_ConstantPoolGetFieldAtIfLoaded");
1783 JvmtiVMObjectAllocEventCollector oam;
1784 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1785 bounds_check(cp, index, CHECK_NULL);
1786 jobject res = get_field_at_helper(cp, index, false, CHECK_NULL);
1791 JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1793 JVMWrapper("JVM_ConstantPoolGetMemberRefInfoAt");
1794 JvmtiVMObjectAllocEventCollector oam;
1795 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1796 bounds_check(cp, index, CHECK_NULL);
1797 constantTag tag = cp->tag_at(index);
1798 if (!tag.is_field_or_method()) {
1799 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1801 int klass_ref = cp->uncached_klass_ref_index_at(index);
1802 symbolHandle klass_name (THREAD, cp->klass_name_at(klass_ref));
1803 symbolHandle member_name(THREAD, cp->uncached_name_ref_at(index));
1804 symbolHandle member_sig (THREAD, cp->uncached_signature_ref_at(index));
1805 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::string_klass(), 3, CHECK_NULL);
1806 objArrayHandle dest(THREAD, dest_o);
1807 Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL);
1808 dest->obj_at_put(0, str());
1809 str = java_lang_String::create_from_symbol(member_name, CHECK_NULL);
1810 dest->obj_at_put(1, str());
1811 str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL);
1812 dest->obj_at_put(2, str());
1813 return (jobjectArray) JNIHandles::make_local(dest());
1817 JVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1819 JVMWrapper("JVM_ConstantPoolGetIntAt");
1820 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1821 bounds_check(cp, index, CHECK_0);
1822 constantTag tag = cp->tag_at(index);
1823 if (!tag.is_int()) {
1824 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1826 return cp->int_at(index);
1830 JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1832 JVMWrapper("JVM_ConstantPoolGetLongAt");
1833 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1834 bounds_check(cp, index, CHECK_(0L));
1835 constantTag tag = cp->tag_at(index);
1836 if (!tag.is_long()) {
1837 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1839 return cp->long_at(index);
1843 JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1845 JVMWrapper("JVM_ConstantPoolGetFloatAt");
1846 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1847 bounds_check(cp, index, CHECK_(0.0f));
1848 constantTag tag = cp->tag_at(index);
1849 if (!tag.is_float()) {
1850 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1852 return cp->float_at(index);
1856 JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1858 JVMWrapper("JVM_ConstantPoolGetDoubleAt");
1859 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1860 bounds_check(cp, index, CHECK_(0.0));
1861 constantTag tag = cp->tag_at(index);
1862 if (!tag.is_double()) {
1863 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1865 return cp->double_at(index);
1869 JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1871 JVMWrapper("JVM_ConstantPoolGetStringAt");
1872 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1873 bounds_check(cp, index, CHECK_NULL);
1874 constantTag tag = cp->tag_at(index);
1875 if (!tag.is_string() && !tag.is_unresolved_string()) {
1876 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1878 oop str = cp->string_at(index, CHECK_NULL);
1879 return (jstring) JNIHandles::make_local(str);
1883 JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index))
1885 JVMWrapper("JVM_ConstantPoolGetUTF8At");
1886 JvmtiVMObjectAllocEventCollector oam;
1887 constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
1888 bounds_check(cp, index, CHECK_NULL);
1889 constantTag tag = cp->tag_at(index);
1890 if (!tag.is_symbol()) {
1891 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1893 symbolOop sym_o = cp->symbol_at(index);
1894 symbolHandle sym(THREAD, sym_o);
1895 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
1896 return (jstring) JNIHandles::make_local(str());
1901 // Assertion support. //////////////////////////////////////////////////////////
1903 JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls))
1904 JVMWrapper("JVM_DesiredAssertionStatus");
1905 assert(cls != NULL, "bad class");
1907 oop r = JNIHandles::resolve(cls);
1908 assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed");
1909 if (java_lang_Class::is_primitive(r)) return false;
1911 klassOop k = java_lang_Class::as_klassOop(r);
1912 assert(Klass::cast(k)->oop_is_instance(), "must be an instance klass");
1913 if (! Klass::cast(k)->oop_is_instance()) return false;
1915 ResourceMark rm(THREAD);
1916 const char* name = Klass::cast(k)->name()->as_C_string();
1917 bool system_class = Klass::cast(k)->class_loader() == NULL;
1918 return JavaAssertions::enabled(name, system_class);
1923 // Return a new AssertionStatusDirectives object with the fields filled in with
1924 // command-line assertion arguments (i.e., -ea, -da).
1925 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
1926 JVMWrapper("JVM_AssertionStatusDirectives");
1927 JvmtiVMObjectAllocEventCollector oam;
1928 oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
1929 return JNIHandles::make_local(env, asd);
1932 // Verification ////////////////////////////////////////////////////////////////////////////////
1934 // Reflection for the verifier /////////////////////////////////////////////////////////////////
1936 // RedefineClasses support: bug 6214132 caused verification to fail.
1937 // All functions from this section should call the jvmtiThreadSate function:
1938 // klassOop class_to_verify_considering_redefinition(klassOop klass).
1939 // The function returns a klassOop of the _scratch_class if the verifier
1940 // was invoked in the middle of the class redefinition.
1941 // Otherwise it returns its argument value which is the _the_class klassOop.
1942 // Please, refer to the description in the jvmtiThreadSate.hpp.
1944 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
1945 JVMWrapper("JVM_GetClassNameUTF");
1946 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
1947 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
1948 return Klass::cast(k)->name()->as_utf8();
1952 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
1953 JVMWrapper("JVM_GetClassCPTypes");
1954 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
1955 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
1956 // types will have length zero if this is not an instanceKlass
1957 // (length is determined by call to JVM_GetClassCPEntriesCount)
1958 if (Klass::cast(k)->oop_is_instance()) {
1959 constantPoolOop cp = instanceKlass::cast(k)->constants();
1960 for (int index = cp->length() - 1; index >= 0; index--) {
1961 constantTag tag = cp->tag_at(index);
1962 types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class :
1963 (tag.is_unresolved_string()) ? JVM_CONSTANT_String : tag.value();
1969 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
1970 JVMWrapper("JVM_GetClassCPEntriesCount");
1971 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
1972 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
1973 if (!Klass::cast(k)->oop_is_instance())
1975 return instanceKlass::cast(k)->constants()->length();
1979 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
1980 JVMWrapper("JVM_GetClassFieldsCount");
1981 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
1982 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
1983 if (!Klass::cast(k)->oop_is_instance())
1985 return instanceKlass::cast(k)->fields()->length() / instanceKlass::next_offset;
1989 JVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls))
1990 JVMWrapper("JVM_GetClassMethodsCount");
1991 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
1992 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
1993 if (!Klass::cast(k)->oop_is_instance())
1995 return instanceKlass::cast(k)->methods()->length();
1999 // The following methods, used for the verifier, are never called with
2000 // array klasses, so a direct cast to instanceKlass is safe.
2001 // Typically, these methods are called in a loop with bounds determined
2002 // by the results of JVM_GetClass{Fields,Methods}Count, which return
2004 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
2005 JVMWrapper("JVM_GetMethodIxExceptionIndexes");
2006 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2007 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2008 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2009 int length = methodOop(method)->checked_exceptions_length();
2011 CheckedExceptionElement* table= methodOop(method)->checked_exceptions_start();
2012 for (int i = 0; i < length; i++) {
2013 exceptions[i] = table[i].class_cp_index;
2019 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index))
2020 JVMWrapper("JVM_GetMethodIxExceptionsCount");
2021 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2022 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2023 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2024 return methodOop(method)->checked_exceptions_length();
2028 JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
2029 JVMWrapper("JVM_GetMethodIxByteCode");
2030 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2031 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2032 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2033 memcpy(code, methodOop(method)->code_base(), methodOop(method)->code_size());
2037 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
2038 JVMWrapper("JVM_GetMethodIxByteCodeLength");
2039 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2040 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2041 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2042 return methodOop(method)->code_size();
2046 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
2047 JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
2048 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2049 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2050 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2051 typeArrayOop extable = methodOop(method)->exception_table();
2052 entry->start_pc = extable->int_at(entry_index * 4);
2053 entry->end_pc = extable->int_at(entry_index * 4 + 1);
2054 entry->handler_pc = extable->int_at(entry_index * 4 + 2);
2055 entry->catchType = extable->int_at(entry_index * 4 + 3);
2059 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
2060 JVMWrapper("JVM_GetMethodIxExceptionTableLength");
2061 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2062 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2063 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2064 return methodOop(method)->exception_table()->length() / 4;
2068 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
2069 JVMWrapper("JVM_GetMethodIxModifiers");
2070 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2071 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2072 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2073 return methodOop(method)->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
2077 JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
2078 JVMWrapper("JVM_GetFieldIxModifiers");
2079 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2080 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2081 typeArrayOop fields = instanceKlass::cast(k)->fields();
2082 return fields->ushort_at(field_index * instanceKlass::next_offset + instanceKlass::access_flags_offset) & JVM_RECOGNIZED_FIELD_MODIFIERS;
2086 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index))
2087 JVMWrapper("JVM_GetMethodIxLocalsCount");
2088 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2089 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2090 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2091 return methodOop(method)->max_locals();
2095 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
2096 JVMWrapper("JVM_GetMethodIxArgsSize");
2097 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2098 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2099 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2100 return methodOop(method)->size_of_parameters();
2104 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2105 JVMWrapper("JVM_GetMethodIxMaxStack");
2106 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2107 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2108 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2109 return methodOop(method)->max_stack();
2113 JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2114 JVMWrapper("JVM_IsConstructorIx");
2115 ResourceMark rm(THREAD);
2116 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2117 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2118 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2119 return methodOop(method)->name() == vmSymbols::object_initializer_name();
2123 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2124 JVMWrapper("JVM_GetMethodIxIxUTF");
2125 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2126 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2127 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2128 return methodOop(method)->name()->as_utf8();
2132 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
2133 JVMWrapper("JVM_GetMethodIxSignatureUTF");
2134 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2135 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2136 oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
2137 return methodOop(method)->signature()->as_utf8();
2141 * All of these JVM_GetCP-xxx methods are used by the old verifier to
2142 * read entries in the constant pool. Since the old verifier always
2143 * works on a copy of the code, it will not see any rewriting that
2144 * may possibly occur in the middle of verification. So it is important
2145 * that nothing it calls tries to use the cpCache instead of the raw
2146 * constant pool, so we must use cp->uncached_x methods when appropriate.
2148 JVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2149 JVMWrapper("JVM_GetCPFieldNameUTF");
2150 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2151 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2152 constantPoolOop cp = instanceKlass::cast(k)->constants();
2153 switch (cp->tag_at(cp_index).value()) {
2154 case JVM_CONSTANT_Fieldref:
2155 return cp->uncached_name_ref_at(cp_index)->as_utf8();
2157 fatal("JVM_GetCPFieldNameUTF: illegal constant");
2159 ShouldNotReachHere();
2164 JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2165 JVMWrapper("JVM_GetCPMethodNameUTF");
2166 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2167 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2168 constantPoolOop cp = instanceKlass::cast(k)->constants();
2169 switch (cp->tag_at(cp_index).value()) {
2170 case JVM_CONSTANT_InterfaceMethodref:
2171 case JVM_CONSTANT_Methodref:
2172 return cp->uncached_name_ref_at(cp_index)->as_utf8();
2174 fatal("JVM_GetCPMethodNameUTF: illegal constant");
2176 ShouldNotReachHere();
2181 JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2182 JVMWrapper("JVM_GetCPMethodSignatureUTF");
2183 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2184 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2185 constantPoolOop cp = instanceKlass::cast(k)->constants();
2186 switch (cp->tag_at(cp_index).value()) {
2187 case JVM_CONSTANT_InterfaceMethodref:
2188 case JVM_CONSTANT_Methodref:
2189 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2191 fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
2193 ShouldNotReachHere();
2198 JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2199 JVMWrapper("JVM_GetCPFieldSignatureUTF");
2200 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2201 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2202 constantPoolOop cp = instanceKlass::cast(k)->constants();
2203 switch (cp->tag_at(cp_index).value()) {
2204 case JVM_CONSTANT_Fieldref:
2205 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2207 fatal("JVM_GetCPFieldSignatureUTF: illegal constant");
2209 ShouldNotReachHere();
2214 JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2215 JVMWrapper("JVM_GetCPClassNameUTF");
2216 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2217 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2218 constantPoolOop cp = instanceKlass::cast(k)->constants();
2219 symbolOop classname = cp->klass_name_at(cp_index);
2220 return classname->as_utf8();
2224 JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2225 JVMWrapper("JVM_GetCPFieldClassNameUTF");
2226 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2227 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2228 constantPoolOop cp = instanceKlass::cast(k)->constants();
2229 switch (cp->tag_at(cp_index).value()) {
2230 case JVM_CONSTANT_Fieldref: {
2231 int class_index = cp->uncached_klass_ref_index_at(cp_index);
2232 symbolOop classname = cp->klass_name_at(class_index);
2233 return classname->as_utf8();
2236 fatal("JVM_GetCPFieldClassNameUTF: illegal constant");
2238 ShouldNotReachHere();
2243 JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2244 JVMWrapper("JVM_GetCPMethodClassNameUTF");
2245 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2246 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2247 constantPoolOop cp = instanceKlass::cast(k)->constants();
2248 switch (cp->tag_at(cp_index).value()) {
2249 case JVM_CONSTANT_Methodref:
2250 case JVM_CONSTANT_InterfaceMethodref: {
2251 int class_index = cp->uncached_klass_ref_index_at(cp_index);
2252 symbolOop classname = cp->klass_name_at(class_index);
2253 return classname->as_utf8();
2256 fatal("JVM_GetCPMethodClassNameUTF: illegal constant");
2258 ShouldNotReachHere();
2263 JVM_QUICK_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
2264 JVMWrapper("JVM_GetCPFieldModifiers");
2265 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2266 klassOop k_called = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(called_cls));
2267 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2268 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
2269 constantPoolOop cp = instanceKlass::cast(k)->constants();
2270 constantPoolOop cp_called = instanceKlass::cast(k_called)->constants();
2271 switch (cp->tag_at(cp_index).value()) {
2272 case JVM_CONSTANT_Fieldref: {
2273 symbolOop name = cp->uncached_name_ref_at(cp_index);
2274 symbolOop signature = cp->uncached_signature_ref_at(cp_index);
2275 typeArrayOop fields = instanceKlass::cast(k_called)->fields();
2276 int fields_count = fields->length();
2277 for (int i = 0; i < fields_count; i += instanceKlass::next_offset) {
2278 if (cp_called->symbol_at(fields->ushort_at(i + instanceKlass::name_index_offset)) == name &&
2279 cp_called->symbol_at(fields->ushort_at(i + instanceKlass::signature_index_offset)) == signature) {
2280 return fields->ushort_at(i + instanceKlass::access_flags_offset) & JVM_RECOGNIZED_FIELD_MODIFIERS;
2286 fatal("JVM_GetCPFieldModifiers: illegal constant");
2288 ShouldNotReachHere();
2293 JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
2294 JVMWrapper("JVM_GetCPMethodModifiers");
2295 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
2296 klassOop k_called = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(called_cls));
2297 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2298 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
2299 constantPoolOop cp = instanceKlass::cast(k)->constants();
2300 switch (cp->tag_at(cp_index).value()) {
2301 case JVM_CONSTANT_Methodref:
2302 case JVM_CONSTANT_InterfaceMethodref: {
2303 symbolOop name = cp->uncached_name_ref_at(cp_index);
2304 symbolOop signature = cp->uncached_signature_ref_at(cp_index);
2305 objArrayOop methods = instanceKlass::cast(k_called)->methods();
2306 int methods_count = methods->length();
2307 for (int i = 0; i < methods_count; i++) {
2308 methodOop method = methodOop(methods->obj_at(i));
2309 if (method->name() == name && method->signature() == signature) {
2310 return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
2316 fatal("JVM_GetCPMethodModifiers: illegal constant");
2318 ShouldNotReachHere();
2323 // Misc //////////////////////////////////////////////////////////////////////////////////////////////
2325 JVM_LEAF(void, JVM_ReleaseUTF(const char *utf))
2326 // So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything
2330 JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2))
2331 JVMWrapper("JVM_IsSameClassPackage");
2332 oop class1_mirror = JNIHandles::resolve_non_null(class1);
2333 oop class2_mirror = JNIHandles::resolve_non_null(class2);
2334 klassOop klass1 = java_lang_Class::as_klassOop(class1_mirror);
2335 klassOop klass2 = java_lang_Class::as_klassOop(class2_mirror);
2336 return (jboolean) Reflection::is_same_class_package(klass1, klass2);
2340 // IO functions ////////////////////////////////////////////////////////////////////////////////////////
2342 JVM_LEAF(jint, JVM_Open(const char *fname, jint flags, jint mode))
2343 JVMWrapper2("JVM_Open (%s)", fname);
2346 int result = hpi::open(fname, flags, mode);
2360 JVM_LEAF(jint, JVM_Close(jint fd))
2361 JVMWrapper2("JVM_Close (0x%x)", fd);
2363 return hpi::close(fd);
2367 JVM_LEAF(jint, JVM_Read(jint fd, char *buf, jint nbytes))
2368 JVMWrapper2("JVM_Read (0x%x)", fd);
2371 return (jint)hpi::read(fd, buf, nbytes);
2375 JVM_LEAF(jint, JVM_Write(jint fd, char *buf, jint nbytes))
2376 JVMWrapper2("JVM_Write (0x%x)", fd);
2379 return (jint)hpi::write(fd, buf, nbytes);
2383 JVM_LEAF(jint, JVM_Available(jint fd, jlong *pbytes))
2384 JVMWrapper2("JVM_Available (0x%x)", fd);
2386 return hpi::available(fd, pbytes);
2390 JVM_LEAF(jlong, JVM_Lseek(jint fd, jlong offset, jint whence))
2391 JVMWrapper4("JVM_Lseek (0x%x, %Ld, %d)", fd, offset, whence);
2393 return hpi::lseek(fd, offset, whence);
2397 JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
2398 JVMWrapper3("JVM_SetLength (0x%x, %Ld)", fd, length);
2399 return hpi::ftruncate(fd, length);
2403 JVM_LEAF(jint, JVM_Sync(jint fd))
2404 JVMWrapper2("JVM_Sync (0x%x)", fd);
2406 return hpi::fsync(fd);
2410 // Printing support //////////////////////////////////////////////////
2413 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
2414 // see bug 4399518, 4417214
2415 if ((intptr_t)count <= 0) return -1;
2416 return vsnprintf(str, count, fmt, args);
2420 int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
2423 va_start(args, fmt);
2424 len = jio_vsnprintf(str, count, fmt, args);
2430 int jio_fprintf(FILE* f, const char *fmt, ...) {
2433 va_start(args, fmt);
2434 len = jio_vfprintf(f, fmt, args);
2440 int jio_vfprintf(FILE* f, const char *fmt, va_list args) {
2441 if (Arguments::vfprintf_hook() != NULL) {
2442 return Arguments::vfprintf_hook()(f, fmt, args);
2444 return vfprintf(f, fmt, args);
2449 int jio_printf(const char *fmt, ...) {
2452 va_start(args, fmt);
2453 len = jio_vfprintf(defaultStream::output_stream(), fmt, args);
2459 // HotSpot specific jio method
2460 void jio_print(const char* s) {
2461 // Try to make this function as atomic as possible.
2462 if (Arguments::vfprintf_hook() != NULL) {
2463 jio_fprintf(defaultStream::output_stream(), "%s", s);
2465 ::write(defaultStream::output_fd(), s, (int)strlen(s));
2471 // java.lang.Thread //////////////////////////////////////////////////////////////////////////////
2473 // In most of the JVM Thread support functions we need to be sure to lock the Threads_lock
2474 // to prevent the target thread from exiting after we have a pointer to the C++ Thread or
2475 // OSThread objects. The exception to this rule is when the target object is the thread
2476 // doing the operation, in which case we know that the thread won't exit until the
2477 // operation is done (all exits being voluntary). There are a few cases where it is
2478 // rather silly to do operations on yourself, like resuming yourself or asking whether
2479 // you are alive. While these can still happen, they are not subject to deadlocks if
2480 // the lock is held while the operation occurs (this is not the case for suspend, for
2481 // instance), and are very unlikely. Because IsAlive needs to be fast and its
2482 // implementation is local to this file, we always lock Threads_lock for that one.
2484 static void thread_entry(JavaThread* thread, TRAPS) {
2485 HandleMark hm(THREAD);
2486 Handle obj(THREAD, thread->threadObj());
2487 JavaValue result(T_VOID);
2488 JavaCalls::call_virtual(&result,
2490 KlassHandle(THREAD, SystemDictionary::thread_klass()),
2491 vmSymbolHandles::run_method_name(),
2492 vmSymbolHandles::void_method_signature(),
2497 JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread))
2498 JVMWrapper("JVM_StartThread");
2499 JavaThread *native_thread = NULL;
2501 // We cannot hold the Threads_lock when we throw an exception,
2502 // due to rank ordering issues. Example: we might need to grab the
2503 // Heap_lock while we construct the exception.
2504 bool throw_illegal_thread_state = false;
2506 // We must release the Threads_lock before we can post a jvmti event
2507 // in Thread::start.
2509 // Ensure that the C++ Thread and OSThread structures aren't freed before
2511 MutexLocker mu(Threads_lock);
2513 // Check to see if we're running a thread that's already exited or was
2514 // stopped (is_stillborn) or is still active (thread is not NULL).
2515 if (java_lang_Thread::is_stillborn(JNIHandles::resolve_non_null(jthread)) ||
2516 java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) {
2517 throw_illegal_thread_state = true;
2520 java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread));
2521 // Allocate the C++ Thread structure and create the native thread. The
2522 // stack size retrieved from java is signed, but the constructor takes
2523 // size_t (an unsigned type), so avoid passing negative values which would
2524 // result in really large stacks.
2525 size_t sz = size > 0 ? (size_t) size : 0;
2526 native_thread = new JavaThread(&thread_entry, sz);
2528 // At this point it may be possible that no osthread was created for the
2529 // JavaThread due to lack of memory. Check for this situation and throw
2530 // an exception if necessary. Eventually we may want to change this so
2531 // that we only grab the lock if the thread was created successfully -
2532 // then we can also do this check and throw the exception in the
2533 // JavaThread constructor.
2534 if (native_thread->osthread() != NULL) {
2535 // Note: the current thread is not being used within "prepare".
2536 native_thread->prepare(jthread);
2541 if (throw_illegal_thread_state) {
2542 THROW(vmSymbols::java_lang_IllegalThreadStateException());
2545 assert(native_thread != NULL, "Starting null thread?");
2547 if (native_thread->osthread() == NULL) {
2548 // No one should hold a reference to the 'native_thread'.
2549 delete native_thread;
2550 if (JvmtiExport::should_post_resource_exhausted()) {
2551 JvmtiExport::post_resource_exhausted(
2552 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS,
2553 "unable to create new native thread");
2555 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
2556 "unable to create new native thread");
2559 Thread::start(native_thread);
2563 // JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints
2564 // before the quasi-asynchronous exception is delivered. This is a little obtrusive,
2565 // but is thought to be reliable and simple. In the case, where the receiver is the
2566 // save thread as the sender, no safepoint is needed.
2567 JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable))
2568 JVMWrapper("JVM_StopThread");
2570 oop java_throwable = JNIHandles::resolve(throwable);
2571 if (java_throwable == NULL) {
2572 THROW(vmSymbols::java_lang_NullPointerException());
2574 oop java_thread = JNIHandles::resolve_non_null(jthread);
2575 JavaThread* receiver = java_lang_Thread::thread(java_thread);
2576 Events::log("JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]", receiver, (address)java_thread, throwable);
2577 // First check if thread already exited
2578 if (receiver != NULL) {
2579 // Check if exception is getting thrown at self (use oop equality, since the
2580 // target object might exit)
2581 if (java_thread == thread->threadObj()) {
2582 // This is a change from JDK 1.1, but JDK 1.2 will also do it:
2583 // NOTE (from JDK 1.2): this is done solely to prevent stopped
2584 // threads from being restarted.
2585 // Fix for 4314342, 4145910, perhaps others: it now doesn't have
2586 // any effect on the "liveness" of a thread; see
2587 // JVM_IsThreadAlive, below.
2588 if (java_throwable->is_a(SystemDictionary::threaddeath_klass())) {
2589 java_lang_Thread::set_stillborn(java_thread);
2591 THROW_OOP(java_throwable);
2593 // Enques a VM_Operation to stop all threads and then deliver the exception...
2594 Thread::send_async_exception(java_thread, JNIHandles::resolve(throwable));
2600 JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread))
2601 JVMWrapper("JVM_IsThreadAlive");
2603 oop thread_oop = JNIHandles::resolve_non_null(jthread);
2604 return java_lang_Thread::is_alive(thread_oop);
2608 JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread))
2609 JVMWrapper("JVM_SuspendThread");
2610 oop java_thread = JNIHandles::resolve_non_null(jthread);
2611 JavaThread* receiver = java_lang_Thread::thread(java_thread);
2613 if (receiver != NULL) {
2614 // thread has run and has not exited (still on threads list)
2617 MutexLockerEx ml(receiver->SR_lock(), Mutex::_no_safepoint_check_flag);
2618 if (receiver->is_external_suspend()) {
2619 // Don't allow nested external suspend requests. We can't return
2620 // an error from this interface so just ignore the problem.
2623 if (receiver->is_exiting()) { // thread is in the process of exiting
2626 receiver->set_external_suspend();
2629 // java_suspend() will catch threads in the process of exiting
2630 // and will ignore them.
2631 receiver->java_suspend();
2633 // It would be nice to have the following assertion in all the
2634 // time, but it is possible for a racing resume request to have
2635 // resumed this thread right after we suspended it. Temporarily
2636 // enable this assertion if you are chasing a different kind of
2639 // assert(java_lang_Thread::thread(receiver->threadObj()) == NULL ||
2640 // receiver->is_being_ext_suspended(), "thread is not suspended");
2645 JVM_ENTRY(void, JVM_ResumeThread(JNIEnv* env, jobject jthread))
2646 JVMWrapper("JVM_ResumeThread");
2647 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate.
2648 // We need to *always* get the threads lock here, since this operation cannot be allowed during
2649 // a safepoint. The safepoint code relies on suspending a thread to examine its state. If other
2650 // threads randomly resumes threads, then a thread might not be suspended when the safepoint code
2652 MutexLocker ml(Threads_lock);
2653 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
2655 // the thread has run and is not in the process of exiting
2661 JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio))
2662 JVMWrapper("JVM_SetThreadPriority");
2663 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
2664 MutexLocker ml(Threads_lock);
2665 oop java_thread = JNIHandles::resolve_non_null(jthread);
2666 java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio);
2667 JavaThread* thr = java_lang_Thread::thread(java_thread);
2668 if (thr != NULL) { // Thread not yet started; priority pushed down when it is
2669 Thread::set_priority(thr, (ThreadPriority)prio);
2674 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
2675 JVMWrapper("JVM_Yield");
2676 if (os::dont_yield()) return;
2677 // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
2678 // Critical for similar threading behaviour
2679 if (ConvertYieldToSleep) {
2680 os::sleep(thread, MinSleepInterval, false);
2687 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
2688 JVMWrapper("JVM_Sleep");
2691 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
2694 if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
2695 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2698 // Save current thread state and restore it at the end of this block.
2699 // And set new thread state to SLEEPING.
2700 JavaThreadSleepState jtss(thread);
2703 // When ConvertSleepToYield is on, this matches the classic VM implementation of
2704 // JVM_Sleep. Critical for similar threading behaviour (Win32)
2705 // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
2707 if (ConvertSleepToYield) {
2710 ThreadState old_state = thread->osthread()->get_state();
2711 thread->osthread()->set_state(SLEEPING);
2712 os::sleep(thread, MinSleepInterval, false);
2713 thread->osthread()->set_state(old_state);
2716 ThreadState old_state = thread->osthread()->get_state();
2717 thread->osthread()->set_state(SLEEPING);
2718 if (os::sleep(thread, millis, true) == OS_INTRPT) {
2719 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
2720 // us while we were sleeping. We do not overwrite those.
2721 if (!HAS_PENDING_EXCEPTION) {
2722 // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
2723 // to properly restore the thread state. That's likely wrong.
2724 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
2727 thread->osthread()->set_state(old_state);
2731 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
2732 JVMWrapper("JVM_CurrentThread");
2733 oop jthread = thread->threadObj();
2734 assert (thread != NULL, "no current thread!");
2735 return JNIHandles::make_local(env, jthread);
2739 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
2740 JVMWrapper("JVM_CountStackFrames");
2742 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
2743 oop java_thread = JNIHandles::resolve_non_null(jthread);
2744 bool throw_illegal_thread_state = false;
2748 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
2749 // We need to re-resolve the java_thread, since a GC might have happened during the
2750 // acquire of the lock
2751 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
2755 } else if(! thr->is_external_suspend() || ! thr->frame_anchor()->walkable()) {
2756 // Check whether this java thread has been suspended already. If not, throws
2757 // IllegalThreadStateException. We defer to throw that exception until
2758 // Threads_lock is released since loading exception class has to leave VM.
2759 // The correct way to test a thread is actually suspended is
2760 // wait_for_ext_suspend_completion(), but we can't call that while holding
2761 // the Threads_lock. The above tests are sufficient for our purposes
2762 // provided the walkability of the stack is stable - which it isn't
2763 // 100% but close enough for most practical purposes.
2764 throw_illegal_thread_state = true;
2766 // Count all java activation, i.e., number of vframes
2767 for(vframeStream vfst(thr); !vfst.at_end(); vfst.next()) {
2768 // Native frames are not counted
2769 if (!vfst.method()->is_native()) count++;
2774 if (throw_illegal_thread_state) {
2775 THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(),
2776 "this thread is not suspended");
2781 // Consider: A better way to implement JVM_Interrupt() is to acquire
2782 // Threads_lock to resolve the jthread into a Thread pointer, fetch
2783 // Thread->platformevent, Thread->native_thr, Thread->parker, etc.,
2784 // drop Threads_lock, and the perform the unpark() and thr_kill() operations
2785 // outside the critical section. Threads_lock is hot so we want to minimize
2786 // the hold-time. A cleaner interface would be to decompose interrupt into
2787 // two steps. The 1st phase, performed under Threads_lock, would return
2788 // a closure that'd be invoked after Threads_lock was dropped.
2789 // This tactic is safe as PlatformEvent and Parkers are type-stable (TSM) and
2790 // admit spurious wakeups.
2792 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
2793 JVMWrapper("JVM_Interrupt");
2795 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
2796 oop java_thread = JNIHandles::resolve_non_null(jthread);
2797 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
2798 // We need to re-resolve the java_thread, since a GC might have happened during the
2799 // acquire of the lock
2800 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
2802 Thread::interrupt(thr);
2807 JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted))
2808 JVMWrapper("JVM_IsInterrupted");
2810 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
2811 oop java_thread = JNIHandles::resolve_non_null(jthread);
2812 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
2813 // We need to re-resolve the java_thread, since a GC might have happened during the
2814 // acquire of the lock
2815 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
2819 return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
2824 // Return true iff the current thread has locked the object passed in
2826 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
2827 JVMWrapper("JVM_HoldsLock");
2828 assert(THREAD->is_Java_thread(), "sanity check");
2830 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
2832 Handle h_obj(THREAD, JNIHandles::resolve(obj));
2833 return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
2837 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
2838 JVMWrapper("JVM_DumpAllStacks");
2840 VMThread::execute(&op);
2841 if (JvmtiExport::should_post_data_dump()) {
2842 JvmtiExport::post_data_dump();
2847 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
2849 static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) {
2850 assert(jthread->is_Java_thread(), "must be a Java thread");
2851 if (jthread->privileged_stack_top() == NULL) return false;
2852 if (jthread->privileged_stack_top()->frame_id() == vfst->frame_id()) {
2853 oop loader = jthread->privileged_stack_top()->class_loader();
2854 if (loader == NULL) return true;
2855 bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
2856 if (trusted) return true;
2861 JVM_ENTRY(jclass, JVM_CurrentLoadedClass(JNIEnv *env))
2862 JVMWrapper("JVM_CurrentLoadedClass");
2863 ResourceMark rm(THREAD);
2865 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
2866 // if a method in a class in a trusted loader is in a doPrivileged, return NULL
2867 bool trusted = is_trusted_frame(thread, &vfst);
2868 if (trusted) return NULL;
2870 methodOop m = vfst.method();
2871 if (!m->is_native()) {
2872 klassOop holder = m->method_holder();
2873 oop loader = instanceKlass::cast(holder)->class_loader();
2874 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
2875 return (jclass) JNIHandles::make_local(env, Klass::cast(holder)->java_mirror());
2883 JVM_ENTRY(jobject, JVM_CurrentClassLoader(JNIEnv *env))
2884 JVMWrapper("JVM_CurrentClassLoader");
2885 ResourceMark rm(THREAD);
2887 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
2889 // if a method in a class in a trusted loader is in a doPrivileged, return NULL
2890 bool trusted = is_trusted_frame(thread, &vfst);
2891 if (trusted) return NULL;
2893 methodOop m = vfst.method();
2894 if (!m->is_native()) {
2895 klassOop holder = m->method_holder();
2896 assert(holder->is_klass(), "just checking");
2897 oop loader = instanceKlass::cast(holder)->class_loader();
2898 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
2899 return JNIHandles::make_local(env, loader);
2907 // Utility object for collecting method holders walking down the stack
2908 class KlassLink: public ResourceObj {
2913 KlassLink(KlassHandle k) { klass = k; next = NULL; }
2917 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
2918 JVMWrapper("JVM_GetClassContext");
2919 ResourceMark rm(THREAD);
2920 JvmtiVMObjectAllocEventCollector oam;
2921 // Collect linked list of (handles to) method holders
2922 KlassLink* first = NULL;
2923 KlassLink* last = NULL;
2926 for(vframeStream vfst(thread); !vfst.at_end(); vfst.security_get_caller_frame(1)) {
2927 // Native frames are not returned
2928 if (!vfst.method()->is_native()) {
2929 klassOop holder = vfst.method()->method_holder();
2930 assert(holder->is_klass(), "just checking");
2932 KlassLink* l = new KlassLink(KlassHandle(thread, holder));
2933 if (first == NULL) {
2942 // Create result array of type [Ljava/lang/Class;
2943 objArrayOop result = oopFactory::new_objArray(SystemDictionary::class_klass(), depth, CHECK_NULL);
2944 // Fill in mirrors corresponding to method holders
2946 while (first != NULL) {
2947 result->obj_at_put(index++, Klass::cast(first->klass())->java_mirror());
2948 first = first->next;
2950 assert(index == depth, "just checking");
2952 return (jobjectArray) JNIHandles::make_local(env, result);
2956 JVM_ENTRY(jint, JVM_ClassDepth(JNIEnv *env, jstring name))
2957 JVMWrapper("JVM_ClassDepth");
2958 ResourceMark rm(THREAD);
2959 Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
2960 Handle class_name_str = java_lang_String::internalize_classname(h_name, CHECK_0);
2962 const char* str = java_lang_String::as_utf8_string(class_name_str());
2963 symbolHandle class_name_sym =
2964 symbolHandle(THREAD, SymbolTable::probe(str, (int)strlen(str)));
2965 if (class_name_sym.is_null()) {
2971 for(vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
2972 if (!vfst.method()->is_native()) {
2973 klassOop holder = vfst.method()->method_holder();
2974 assert(holder->is_klass(), "just checking");
2975 if (instanceKlass::cast(holder)->name() == class_name_sym()) {
2985 JVM_ENTRY(jint, JVM_ClassLoaderDepth(JNIEnv *env))
2986 JVMWrapper("JVM_ClassLoaderDepth");
2987 ResourceMark rm(THREAD);
2989 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
2990 // if a method in a class in a trusted loader is in a doPrivileged, return -1
2991 bool trusted = is_trusted_frame(thread, &vfst);
2992 if (trusted) return -1;
2994 methodOop m = vfst.method();
2995 if (!m->is_native()) {
2996 klassOop holder = m->method_holder();
2997 assert(holder->is_klass(), "just checking");
2998 oop loader = instanceKlass::cast(holder)->class_loader();
2999 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
3009 // java.lang.Package ////////////////////////////////////////////////////////////////
3012 JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name))
3013 JVMWrapper("JVM_GetSystemPackage");
3014 ResourceMark rm(THREAD);
3015 JvmtiVMObjectAllocEventCollector oam;
3016 char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
3017 oop result = ClassLoader::get_system_package(str, CHECK_NULL);
3018 return (jstring) JNIHandles::make_local(result);
3022 JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env))
3023 JVMWrapper("JVM_GetSystemPackages");
3024 JvmtiVMObjectAllocEventCollector oam;
3025 objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL);
3026 return (jobjectArray) JNIHandles::make_local(result);
3030 // ObjectInputStream ///////////////////////////////////////////////////////////////
3032 bool force_verify_field_access(klassOop current_class, klassOop field_class, AccessFlags access, bool classloader_only) {
3033 if (current_class == NULL) {
3036 if ((current_class == field_class) || access.is_public()) {
3040 if (access.is_protected()) {
3041 // See if current_class is a subclass of field_class
3042 if (Klass::cast(current_class)->is_subclass_of(field_class)) {
3047 return (!access.is_private() && instanceKlass::cast(current_class)->is_same_class_package(field_class));
3051 // JVM_AllocateNewObject and JVM_AllocateNewArray are unused as of 1.4
3052 JVM_ENTRY(jobject, JVM_AllocateNewObject(JNIEnv *env,