jvm.cpp revision 3879
0N/A/*
2273N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/classLoader.hpp"
1879N/A#include "classfile/javaAssertions.hpp"
1879N/A#include "classfile/javaClasses.hpp"
1879N/A#include "classfile/symbolTable.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "classfile/vmSymbols.hpp"
1879N/A#include "gc_interface/collectedHeap.inline.hpp"
1879N/A#include "memory/oopFactory.hpp"
1879N/A#include "memory/universe.inline.hpp"
1879N/A#include "oops/fieldStreams.hpp"
1879N/A#include "oops/instanceKlass.hpp"
1879N/A#include "oops/objArrayKlass.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A#include "prims/jvm.h"
1879N/A#include "prims/jvm_misc.hpp"
1879N/A#include "prims/jvmtiExport.hpp"
0N/A#include "prims/jvmtiThreadState.hpp"
0N/A#include "prims/nativeLookup.hpp"
0N/A#include "prims/privilegedStack.hpp"
0N/A#include "runtime/arguments.hpp"
0N/A#include "runtime/dtraceJSDT.hpp"
0N/A#include "runtime/handles.inline.hpp"
0N/A#include "runtime/init.hpp"
0N/A#include "runtime/interfaceSupport.hpp"
605N/A#include "runtime/java.hpp"
0N/A#include "runtime/javaCalls.hpp"
0N/A#include "runtime/jfieldIDWorkaround.hpp"
0N/A#include "runtime/os.hpp"
0N/A#include "runtime/perfData.hpp"
0N/A#include "runtime/reflection.hpp"
0N/A#include "runtime/vframe.hpp"
0N/A#include "runtime/vm_operations.hpp"
0N/A#include "services/attachListener.hpp"
0N/A#include "services/management.hpp"
0N/A#include "services/threadService.hpp"
605N/A#include "utilities/copy.hpp"
0N/A#include "utilities/defaultStream.hpp"
0N/A#include "utilities/dtrace.hpp"
0N/A#include "utilities/events.hpp"
0N/A#include "utilities/histogram.hpp"
0N/A#include "utilities/top.hpp"
0N/A#include "utilities/utf8.hpp"
0N/A#ifdef TARGET_OS_FAMILY_linux
0N/A# include "jvm_linux.h"
0N/A#endif
0N/A#ifdef TARGET_OS_FAMILY_solaris
0N/A# include "jvm_solaris.h"
0N/A#endif
0N/A#ifdef TARGET_OS_FAMILY_windows
0N/A# include "jvm_windows.h"
0N/A#endif
0N/A#ifdef TARGET_OS_FAMILY_bsd
0N/A# include "jvm_bsd.h"
0N/A#endif
0N/A
0N/A#include <errno.h>
0N/A
0N/A#ifndef USDT2
0N/AHS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
221N/AHS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
221N/AHS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
221N/A#endif /* !USDT2 */
0N/A
0N/A/*
0N/A NOTE about use of any ctor or function call that can trigger a safepoint/GC:
113N/A such ctors and calls MUST NOT come between an oop declaration/init and its
0N/A usage because if objects are move this may cause various memory stomps, bus
0N/A errors and segfaults. Here is a cookbook for causing so called "naked oop
0N/A failures":
0N/A
0N/A JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
0N/A JVMWrapper("JVM_GetClassDeclaredFields");
0N/A
0N/A // Object address to be held directly in mirror & not visible to GC
0N/A oop mirror = JNIHandles::resolve_non_null(ofClass);
0N/A
0N/A // If this ctor can hit a safepoint, moving objects around, then
0N/A ComplexConstructor foo;
0N/A
0N/A // Boom! mirror may point to JUNK instead of the intended object
0N/A (some dereference of mirror)
0N/A
0N/A // Here's another call that may block for GC, making mirror stale
0N/A MutexLocker ml(some_lock);
0N/A
0N/A // And here's an initializer that can result in a stale oop
0N/A // all in one step.
0N/A oop o = call_that_can_throw_exception(TRAPS);
0N/A
0N/A
0N/A The solution is to keep the oop declaration BELOW the ctor or function
0N/A call that might cause a GC, do another resolve to reassign the oop, or
129N/A consider use of a Handle instead of an oop so there is immunity from object
129N/A motion. But note that the "QUICK" entries below do not have a handlemark
366N/A and thus can only support use of handles passed in.
129N/A*/
129N/A
129N/Astatic void trace_class_resolution_impl(klassOop to_class, TRAPS) {
129N/A ResourceMark rm;
129N/A int line_number = -1;
366N/A const char * source_file = NULL;
366N/A const char * trace = "explicit";
366N/A klassOop caller = NULL;
129N/A JavaThread* jthread = JavaThread::current();
129N/A if (jthread->has_last_Java_frame()) {
129N/A vframeStream vfst(jthread);
129N/A
129N/A // scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames
0N/A TempNewSymbol access_controller = SymbolTable::new_symbol("java/security/AccessController", CHECK);
0N/A klassOop access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK);
0N/A TempNewSymbol privileged_action = SymbolTable::new_symbol("java/security/PrivilegedAction", CHECK);
0N/A klassOop privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK);
0N/A
0N/A methodOop last_caller = NULL;
0N/A
0N/A while (!vfst.at_end()) {
0N/A methodOop m = vfst.method();
0N/A if (!vfst.method()->method_holder()->klass_part()->is_subclass_of(SystemDictionary::ClassLoader_klass())&&
0N/A !vfst.method()->method_holder()->klass_part()->is_subclass_of(access_controller_klass) &&
0N/A !vfst.method()->method_holder()->klass_part()->is_subclass_of(privileged_action_klass)) {
0N/A break;
0N/A }
0N/A last_caller = m;
0N/A vfst.next();
0N/A }
0N/A // if this is called from Class.forName0 and that is called from Class.forName,
0N/A // then print the caller of Class.forName. If this is Class.loadClass, then print
0N/A // that caller, otherwise keep quiet since this should be picked up elsewhere.
0N/A bool found_it = false;
0N/A if (!vfst.at_end() &&
366N/A instanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class() &&
0N/A vfst.method()->name() == vmSymbols::forName0_name()) {
0N/A vfst.next();
366N/A if (!vfst.at_end() &&
366N/A instanceKlass::cast(vfst.method()->method_holder())->name() == vmSymbols::java_lang_Class() &&
366N/A vfst.method()->name() == vmSymbols::forName_name()) {
0N/A vfst.next();
0N/A found_it = true;
0N/A }
0N/A } else if (last_caller != NULL &&
0N/A instanceKlass::cast(last_caller->method_holder())->name() ==
0N/A vmSymbols::java_lang_ClassLoader() &&
0N/A (last_caller->name() == vmSymbols::loadClassInternal_name() ||
0N/A last_caller->name() == vmSymbols::loadClass_name())) {
0N/A found_it = true;
0N/A } else if (!vfst.at_end()) {
0N/A if (vfst.method()->is_native()) {
0N/A // JNI call
0N/A found_it = true;
0N/A }
0N/A }
0N/A if (found_it && !vfst.at_end()) {
0N/A // found the caller
0N/A caller = vfst.method()->method_holder();
0N/A line_number = vfst.method()->line_number_from_bci(vfst.bci());
0N/A if (line_number == -1) {
0N/A // show method name if it's a native method
0N/A trace = vfst.method()->name_and_sig_as_C_string();
0N/A }
0N/A Symbol* s = instanceKlass::cast(caller)->source_file_name();
0N/A if (s != NULL) {
0N/A source_file = s->as_C_string();
0N/A }
0N/A }
0N/A }
0N/A if (caller != NULL) {
0N/A if (to_class != caller) {
0N/A const char * from = Klass::cast(caller)->external_name();
0N/A const char * to = Klass::cast(to_class)->external_name();
0N/A // print in a single call to reduce interleaving between threads
0N/A if (source_file != NULL) {
0N/A tty->print("RESOLVE %s %s %s:%d (%s)\n", from, to, source_file, line_number, trace);
0N/A } else {
0N/A tty->print("RESOLVE %s %s (%s)\n", from, to, trace);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid trace_class_resolution(klassOop to_class) {
0N/A EXCEPTION_MARK;
0N/A trace_class_resolution_impl(to_class, THREAD);
0N/A if (HAS_PENDING_EXCEPTION) {
0N/A CLEAR_PENDING_EXCEPTION;
0N/A }
0N/A}
0N/A
0N/A// Wrapper to trace JVM functions
0N/A
0N/A#ifdef ASSERT
0N/A class JVMTraceWrapper : public StackObj {
0N/A public:
0N/A JVMTraceWrapper(const char* format, ...) {
0N/A if (TraceJVMCalls) {
0N/A va_list ap;
0N/A va_start(ap, format);
0N/A tty->print("JVM ");
0N/A tty->vprint_cr(format, ap);
0N/A va_end(ap);
0N/A }
0N/A }
0N/A };
0N/A
0N/A Histogram* JVMHistogram;
0N/A volatile jint JVMHistogram_lock = 0;
0N/A
0N/A class JVMHistogramElement : public HistogramElement {
0N/A public:
0N/A JVMHistogramElement(const char* name);
0N/A };
0N/A
0N/A JVMHistogramElement::JVMHistogramElement(const char* elementName) {
0N/A _name = elementName;
0N/A uintx count = 0;
0N/A
0N/A while (Atomic::cmpxchg(1, &JVMHistogram_lock, 0) != 0) {
0N/A while (OrderAccess::load_acquire(&JVMHistogram_lock) != 0) {
0N/A count +=1;
0N/A if ( (WarnOnStalledSpinLock > 0)
0N/A && (count % WarnOnStalledSpinLock == 0)) {
0N/A warning("JVMHistogram_lock seems to be stalled");
0N/A }
0N/A }
0N/A }
0N/A
0N/A if(JVMHistogram == NULL)
0N/A JVMHistogram = new Histogram("JVM Call Counts",100);
0N/A
0N/A JVMHistogram->add_element(this);
0N/A Atomic::dec(&JVMHistogram_lock);
0N/A }
0N/A
0N/A #define JVMCountWrapper(arg) \
0N/A static JVMHistogramElement* e = new JVMHistogramElement(arg); \
0N/A if (e != NULL) e->increment_count(); // Due to bug in VC++, we need a NULL check here eventhough it should never happen!
0N/A
0N/A #define JVMWrapper(arg1) JVMCountWrapper(arg1); JVMTraceWrapper(arg1)
0N/A #define JVMWrapper2(arg1, arg2) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2)
0N/A #define JVMWrapper3(arg1, arg2, arg3) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3)
0N/A #define JVMWrapper4(arg1, arg2, arg3, arg4) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3, arg4)
0N/A#else
0N/A #define JVMWrapper(arg1)
0N/A #define JVMWrapper2(arg1, arg2)
0N/A #define JVMWrapper3(arg1, arg2, arg3)
0N/A #define JVMWrapper4(arg1, arg2, arg3, arg4)
0N/A#endif
0N/A
0N/A
0N/A// Interface version /////////////////////////////////////////////////////////////////////
0N/A
0N/A
0N/AJVM_LEAF(jint, JVM_GetInterfaceVersion())
0N/A return JVM_INTERFACE_VERSION;
0N/AJVM_END
0N/A
0N/A
0N/A// java.lang.System //////////////////////////////////////////////////////////////////////
0N/A
0N/A
0N/AJVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
0N/A JVMWrapper("JVM_CurrentTimeMillis");
0N/A return os::javaTimeMillis();
0N/AJVM_END
0N/A
0N/AJVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
0N/A JVMWrapper("JVM_NanoTime");
0N/A return os::javaTimeNanos();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
0N/A jobject dst, jint dst_pos, jint length))
0N/A JVMWrapper("JVM_ArrayCopy");
0N/A // Check if we have null pointers
0N/A if (src == NULL || dst == NULL) {
0N/A THROW(vmSymbols::java_lang_NullPointerException());
0N/A }
0N/A arrayOop s = arrayOop(JNIHandles::resolve_non_null(src));
0N/A arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst));
0N/A assert(s->is_oop(), "JVM_ArrayCopy: src not an oop");
0N/A assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop");
0N/A // Do copy
0N/A Klass::cast(s->klass())->copy_array(s, src_pos, d, dst_pos, length, thread);
0N/AJVM_END
0N/A
0N/A
0N/Astatic void set_property(Handle props, const char* key, const char* value, TRAPS) {
0N/A JavaValue r(T_OBJECT);
0N/A // public synchronized Object put(Object key, Object value);
0N/A HandleMark hm(THREAD);
0N/A Handle key_str = java_lang_String::create_from_platform_dependent_str(key, CHECK);
0N/A Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK);
0N/A JavaCalls::call_virtual(&r,
0N/A props,
0N/A KlassHandle(THREAD, SystemDictionary::Properties_klass()),
0N/A vmSymbols::put_name(),
0N/A vmSymbols::object_object_object_signature(),
0N/A key_str,
0N/A value_str,
0N/A THREAD);
0N/A}
0N/A
0N/A
0N/A#define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties));
0N/A
0N/A
0N/AJVM_ENTRY(jobject, JVM_InitProperties(JNIEnv *env, jobject properties))
0N/A JVMWrapper("JVM_InitProperties");
0N/A ResourceMark rm;
0N/A
0N/A Handle props(THREAD, JNIHandles::resolve_non_null(properties));
0N/A
0N/A // System property list includes both user set via -D option and
0N/A // jvm system specific properties.
0N/A for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
0N/A PUTPROP(props, p->key(), p->value());
0N/A }
0N/A
0N/A // Convert the -XX:MaxDirectMemorySize= command line flag
0N/A // to the sun.nio.MaxDirectMemorySize property.
0N/A // Do this after setting user properties to prevent people
0N/A // from setting the value with a -D option, as requested.
0N/A {
0N/A char as_chars[256];
0N/A jio_snprintf(as_chars, sizeof(as_chars), INTX_FORMAT, MaxDirectMemorySize);
0N/A PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars);
0N/A }
0N/A
0N/A // JVM monitoring and management support
0N/A // Add the sun.management.compiler property for the compiler's name
0N/A {
0N/A#undef CSIZE
0N/A#if defined(_LP64) || defined(_WIN64)
0N/A #define CSIZE "64-Bit "
0N/A#else
0N/A #define CSIZE
0N/A#endif // 64bit
0N/A
0N/A#ifdef TIERED
0N/A const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers";
0N/A#else
0N/A#if defined(COMPILER1)
0N/A const char* compiler_name = "HotSpot " CSIZE "Client Compiler";
0N/A#elif defined(COMPILER2)
0N/A const char* compiler_name = "HotSpot " CSIZE "Server Compiler";
0N/A#else
0N/A const char* compiler_name = "";
0N/A#endif // compilers
0N/A#endif // TIERED
0N/A
0N/A if (*compiler_name != '\0' &&
0N/A (Arguments::mode() != Arguments::_int)) {
0N/A PUTPROP(props, "sun.management.compiler", compiler_name);
0N/A }
0N/A }
0N/A
0N/A return properties;
0N/AJVM_END
0N/A
0N/A
0N/A// java.lang.Runtime /////////////////////////////////////////////////////////////////////////
0N/A
0N/Aextern volatile jint vm_created;
0N/A
0N/AJVM_ENTRY_NO_ENV(void, JVM_Exit(jint code))
0N/A if (vm_created != 0 && (code == 0)) {
0N/A // The VM is about to exit. We call back into Java to check whether finalizers should be run
0N/A Universe::run_finalizers_on_exit();
0N/A }
0N/A before_exit(thread);
0N/A vm_exit(code);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
0N/A before_exit(thread);
0N/A vm_exit(code);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(void, JVM_OnExit(void (*func)(void)))
0N/A register_on_exit_function(func);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY_NO_ENV(void, JVM_GC(void))
0N/A JVMWrapper("JVM_GC");
0N/A if (!DisableExplicitGC) {
0N/A Universe::heap()->collect(GCCause::_java_lang_system_gc);
0N/A }
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void))
0N/A JVMWrapper("JVM_MaxObjectInspectionAge");
0N/A return Universe::heap()->millis_since_last_gc();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(void, JVM_TraceInstructions(jboolean on))
0N/A if (PrintJVMWarnings) warning("JVM_TraceInstructions not supported");
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(void, JVM_TraceMethodCalls(jboolean on))
0N/A if (PrintJVMWarnings) warning("JVM_TraceMethodCalls not supported");
0N/AJVM_END
0N/A
0N/Astatic inline jlong convert_size_t_to_jlong(size_t val) {
0N/A // In the 64-bit vm, a size_t can overflow a jlong (which is signed).
0N/A NOT_LP64 (return (jlong)val;)
0N/A LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);)
0N/A}
0N/A
0N/AJVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void))
0N/A JVMWrapper("JVM_TotalMemory");
0N/A size_t n = Universe::heap()->capacity();
0N/A return convert_size_t_to_jlong(n);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void))
0N/A JVMWrapper("JVM_FreeMemory");
0N/A CollectedHeap* ch = Universe::heap();
0N/A size_t n;
0N/A {
0N/A MutexLocker x(Heap_lock);
0N/A n = ch->capacity() - ch->used();
0N/A }
0N/A return convert_size_t_to_jlong(n);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
0N/A JVMWrapper("JVM_MaxMemory");
0N/A size_t n = Universe::heap()->max_capacity();
0N/A return convert_size_t_to_jlong(n);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
0N/A JVMWrapper("JVM_ActiveProcessorCount");
0N/A return os::active_processor_count();
0N/AJVM_END
0N/A
0N/A
0N/A
0N/A// java.lang.Throwable //////////////////////////////////////////////////////
0N/A
0N/A
0N/AJVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
0N/A JVMWrapper("JVM_FillInStackTrace");
0N/A Handle exception(thread, JNIHandles::resolve_non_null(receiver));
0N/A java_lang_Throwable::fill_in_stack_trace(exception);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(void, JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable))
0N/A JVMWrapper("JVM_PrintStackTrace");
0N/A // Note: This is no longer used in Merlin, but we still support it for compatibility.
0N/A oop exception = JNIHandles::resolve_non_null(receiver);
0N/A oop stream = JNIHandles::resolve_non_null(printable);
0N/A java_lang_Throwable::print_stack_trace(exception, stream);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jint, JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable))
0N/A JVMWrapper("JVM_GetStackTraceDepth");
0N/A oop exception = JNIHandles::resolve(throwable);
0N/A return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
0N/A JVMWrapper("JVM_GetStackTraceElement");
0N/A JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
0N/A oop exception = JNIHandles::resolve(throwable);
0N/A oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
0N/A return JNIHandles::make_local(env, element);
0N/AJVM_END
0N/A
0N/A
0N/A// java.lang.Object ///////////////////////////////////////////////
0N/A
0N/A
0N/AJVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
0N/A JVMWrapper("JVM_IHashCode");
0N/A // as implemented in the classic virtual machine; return 0 if object is NULL
0N/A return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
0N/A JVMWrapper("JVM_MonitorWait");
0N/A Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
0N/A assert(obj->is_instance() || obj->is_array(), "JVM_MonitorWait must apply to an object");
0N/A JavaThreadInObjectWaitState jtiows(thread, ms != 0);
0N/A if (JvmtiExport::should_post_monitor_wait()) {
0N/A JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
0N/A }
0N/A ObjectSynchronizer::wait(obj, ms, CHECK);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
0N/A JVMWrapper("JVM_MonitorNotify");
0N/A Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
0N/A assert(obj->is_instance() || obj->is_array(), "JVM_MonitorNotify must apply to an object");
0N/A ObjectSynchronizer::notify(obj, CHECK);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
0N/A JVMWrapper("JVM_MonitorNotifyAll");
0N/A Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
0N/A assert(obj->is_instance() || obj->is_array(), "JVM_MonitorNotifyAll must apply to an object");
0N/A ObjectSynchronizer::notifyall(obj, CHECK);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
0N/A JVMWrapper("JVM_Clone");
0N/A Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
0N/A const KlassHandle klass (THREAD, obj->klass());
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A
0N/A#ifdef ASSERT
0N/A // Just checking that the cloneable flag is set correct
0N/A if (obj->is_javaArray()) {
0N/A guarantee(klass->is_cloneable(), "all arrays are cloneable");
0N/A } else {
0N/A guarantee(obj->is_instance(), "should be instanceOop");
0N/A bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
0N/A guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
0N/A }
0N/A#endif
0N/A
0N/A // Check if class of obj supports the Cloneable interface.
0N/A // All arrays are considered to be cloneable (See JLS 20.1.5)
0N/A if (!klass->is_cloneable()) {
0N/A ResourceMark rm(THREAD);
0N/A THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
0N/A }
0N/A
0N/A // Make shallow object copy
0N/A const int size = obj->size();
0N/A oop new_obj = NULL;
0N/A if (obj->is_javaArray()) {
0N/A const int length = ((arrayOop)obj())->length();
0N/A new_obj = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
0N/A } else {
0N/A new_obj = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
0N/A }
0N/A // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
0N/A // is modifying a reference field in the clonee, a non-oop-atomic copy might
0N/A // be suspended in the middle of copying the pointer and end up with parts
0N/A // of two different pointers in the field. Subsequent dereferences will crash.
0N/A // 4846409: an oop-copy of objects with long or double fields or arrays of same
0N/A // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
0N/A // of oops. We know objects are aligned on a minimum of an jlong boundary.
0N/A // The same is true of StubRoutines::object_copy and the various oop_copy
0N/A // variants, and of the code generated by the inline_native_clone intrinsic.
0N/A assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
0N/A Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj,
0N/A (size_t)align_object_size(size) / HeapWordsPerLong);
0N/A // Clear the header
0N/A new_obj->init_mark();
0N/A
0N/A // Store check (mark entire object and let gc sort it out)
0N/A BarrierSet* bs = Universe::heap()->barrier_set();
0N/A assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
0N/A bs->write_region(MemRegion((HeapWord*)new_obj, size));
0N/A
0N/A // Caution: this involves a java upcall, so the clone should be
0N/A // "gc-robust" by this stage.
0N/A if (klass->has_finalizer()) {
0N/A assert(obj->is_instance(), "should be instanceOop");
0N/A new_obj = instanceKlass::register_finalizer(instanceOop(new_obj), CHECK_NULL);
0N/A }
0N/A
0N/A return JNIHandles::make_local(env, oop(new_obj));
0N/AJVM_END
0N/A
0N/A// java.lang.Compiler ////////////////////////////////////////////////////
0N/A
0N/A// The initial cuts of the HotSpot VM will not support JITs, and all existing
0N/A// JITs would need extensive changes to work with HotSpot. The JIT-related JVM
0N/A// functions are all silently ignored unless JVM warnings are printed.
0N/A
0N/AJVM_LEAF(void, JVM_InitializeCompiler (JNIEnv *env, jclass compCls))
0N/A if (PrintJVMWarnings) warning("JVM_InitializeCompiler not supported");
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(jboolean, JVM_IsSilentCompiler(JNIEnv *env, jclass compCls))
0N/A if (PrintJVMWarnings) warning("JVM_IsSilentCompiler not supported");
0N/A return JNI_FALSE;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(jboolean, JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls))
0N/A if (PrintJVMWarnings) warning("JVM_CompileClass not supported");
0N/A return JNI_FALSE;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(jboolean, JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname))
0N/A if (PrintJVMWarnings) warning("JVM_CompileClasses not supported");
0N/A return JNI_FALSE;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(jobject, JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg))
0N/A if (PrintJVMWarnings) warning("JVM_CompilerCommand not supported");
0N/A return NULL;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(void, JVM_EnableCompiler(JNIEnv *env, jclass compCls))
0N/A if (PrintJVMWarnings) warning("JVM_EnableCompiler not supported");
0N/AJVM_END
0N/A
0N/A
0N/AJVM_LEAF(void, JVM_DisableCompiler(JNIEnv *env, jclass compCls))
0N/A if (PrintJVMWarnings) warning("JVM_DisableCompiler not supported");
0N/AJVM_END
0N/A
0N/A
0N/A
0N/A// Error message support //////////////////////////////////////////////////////
0N/A
0N/AJVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len))
0N/A JVMWrapper("JVM_GetLastErrorString");
0N/A return (jint)os::lasterror(buf, len);
0N/AJVM_END
0N/A
0N/A
0N/A// java.io.File ///////////////////////////////////////////////////////////////
0N/A
0N/AJVM_LEAF(char*, JVM_NativePath(char* path))
0N/A JVMWrapper2("JVM_NativePath (%s)", path);
0N/A return os::native_path(path);
0N/AJVM_END
0N/A
0N/A
0N/A// Misc. class handling ///////////////////////////////////////////////////////////
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
0N/A JVMWrapper("JVM_GetCallerClass");
0N/A klassOop k = thread->security_get_caller_class(depth);
0N/A return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
0N/A JVMWrapper("JVM_FindPrimitiveClass");
0N/A oop mirror = NULL;
0N/A BasicType t = name2type(utf);
0N/A if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
0N/A mirror = Universe::java_mirror(t);
0N/A }
0N/A if (mirror == NULL) {
0N/A THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
0N/A } else {
0N/A return (jclass) JNIHandles::make_local(env, mirror);
0N/A }
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls))
0N/A JVMWrapper("JVM_ResolveClass");
0N/A if (PrintJVMWarnings) warning("JVM_ResolveClass not implemented");
0N/AJVM_END
0N/A
0N/A
0N/A// Returns a class loaded by the bootstrap class loader; or null
0N/A// if not found. ClassNotFoundException is not thrown.
0N/A//
0N/A// Rationale behind JVM_FindClassFromBootLoader
0N/A// a> JVM_FindClassFromClassLoader was never exported in the export tables.
0N/A// b> because of (a) java.dll has a direct dependecy on the unexported
0N/A// private symbol "_JVM_FindClassFromClassLoader@20".
0N/A// c> the launcher cannot use the private symbol as it dynamically opens
0N/A// the entry point, so if something changes, the launcher will fail
0N/A// unexpectedly at runtime, it is safest for the launcher to dlopen a
0N/A// stable exported interface.
0N/A// d> re-exporting JVM_FindClassFromClassLoader as public, will cause its
0N/A// signature to change from _JVM_FindClassFromClassLoader@20 to
0N/A// JVM_FindClassFromClassLoader and will not be backward compatible
0N/A// with older JDKs.
0N/A// Thus a public/stable exported entry point is the right solution,
0N/A// public here means public in linker semantics, and is exported only
0N/A// to the JDK, and is not intended to be a public API.
0N/A
0N/AJVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
0N/A const char* name))
0N/A JVMWrapper2("JVM_FindClassFromBootLoader %s", name);
0N/A
0N/A // Java libraries should ensure that name is never null...
0N/A if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
0N/A // It's impossible to create this class; the name cannot fit
0N/A // into the constant pool.
0N/A return NULL;
0N/A }
0N/A
0N/A TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
0N/A klassOop k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL);
0N/A if (k == NULL) {
0N/A return NULL;
0N/A }
0N/A
0N/A if (TraceClassResolution) {
0N/A trace_class_resolution(k);
0N/A }
0N/A return (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name,
0N/A jboolean init, jobject loader,
0N/A jboolean throwError))
0N/A JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name,
0N/A throwError ? "error" : "exception");
0N/A // Java libraries should ensure that name is never null...
0N/A if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
0N/A // It's impossible to create this class; the name cannot fit
0N/A // into the constant pool.
0N/A if (throwError) {
0N/A THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
0N/A } else {
0N/A THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
0N/A }
0N/A }
0N/A TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
0N/A Handle h_loader(THREAD, JNIHandles::resolve(loader));
0N/A jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
0N/A Handle(), throwError, THREAD);
0N/A
0N/A if (TraceClassResolution && result != NULL) {
0N/A trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result)));
0N/A }
0N/A return result;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name,
0N/A jboolean init, jclass from))
0N/A JVMWrapper2("JVM_FindClassFromClass %s", name);
0N/A if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
0N/A // It's impossible to create this class; the name cannot fit
0N/A // into the constant pool.
0N/A THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
0N/A }
0N/A TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
0N/A oop from_class_oop = JNIHandles::resolve(from);
0N/A klassOop from_class = (from_class_oop == NULL)
0N/A ? (klassOop)NULL
0N/A : java_lang_Class::as_klassOop(from_class_oop);
0N/A oop class_loader = NULL;
0N/A oop protection_domain = NULL;
0N/A if (from_class != NULL) {
0N/A class_loader = Klass::cast(from_class)->class_loader();
0N/A protection_domain = Klass::cast(from_class)->protection_domain();
0N/A }
0N/A Handle h_loader(THREAD, class_loader);
0N/A Handle h_prot (THREAD, protection_domain);
0N/A jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
0N/A h_prot, true, thread);
0N/A
0N/A if (TraceClassResolution && result != NULL) {
0N/A // this function is generally only used for class loading during verification.
0N/A ResourceMark rm;
0N/A oop from_mirror = JNIHandles::resolve_non_null(from);
0N/A klassOop from_class = java_lang_Class::as_klassOop(from_mirror);
0N/A const char * from_name = Klass::cast(from_class)->external_name();
0N/A
0N/A oop mirror = JNIHandles::resolve_non_null(result);
0N/A klassOop to_class = java_lang_Class::as_klassOop(mirror);
0N/A const char * to = Klass::cast(to_class)->external_name();
0N/A tty->print("RESOLVE %s %s (verification)\n", from_name, to);
0N/A }
0N/A
0N/A return result;
0N/AJVM_END
0N/A
0N/Astatic void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) {
0N/A if (loader.is_null()) {
0N/A return;
0N/A }
0N/A
0N/A // check whether the current caller thread holds the lock or not.
0N/A // If not, increment the corresponding counter
0N/A if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader) !=
0N/A ObjectSynchronizer::owner_self) {
0N/A counter->inc();
0N/A }
0N/A}
0N/A
0N/A// common code for JVM_DefineClass() and JVM_DefineClassWithSource()
0N/A// and JVM_DefineClassWithSourceCond()
0N/Astatic jclass jvm_define_class_common(JNIEnv *env, const char *name,
0N/A jobject loader, const jbyte *buf,
0N/A jsize len, jobject pd, const char *source,
0N/A jboolean verify, TRAPS) {
0N/A if (source == NULL) source = "__JVM_DefineClass__";
0N/A
0N/A assert(THREAD->is_Java_thread(), "must be a JavaThread");
0N/A JavaThread* jt = (JavaThread*) THREAD;
0N/A
0N/A PerfClassTraceTime vmtimer(ClassLoader::perf_define_appclass_time(),
0N/A ClassLoader::perf_define_appclass_selftime(),
0N/A ClassLoader::perf_define_appclasses(),
0N/A jt->get_thread_stat()->perf_recursion_counts_addr(),
0N/A jt->get_thread_stat()->perf_timers_addr(),
0N/A PerfClassTraceTime::DEFINE_CLASS);
0N/A
0N/A if (UsePerfData) {
0N/A ClassLoader::perf_app_classfile_bytes_read()->inc(len);
0N/A }
0N/A
0N/A // Since exceptions can be thrown, class initialization can take place
0N/A // if name is NULL no check for class name in .class stream has to be made.
0N/A TempNewSymbol class_name = NULL;
0N/A if (name != NULL) {
0N/A const int str_len = (int)strlen(name);
0N/A if (str_len > Symbol::max_length()) {
0N/A // It's impossible to create this class; the name cannot fit
0N/A // into the constant pool.
0N/A THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
0N/A }
0N/A class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL);
0N/A }
0N/A
0N/A ResourceMark rm(THREAD);
0N/A ClassFileStream st((u1*) buf, len, (char *)source);
0N/A Handle class_loader (THREAD, JNIHandles::resolve(loader));
0N/A if (UsePerfData) {
0N/A is_lock_held_by_thread(class_loader,
0N/A ClassLoader::sync_JVMDefineClassLockFreeCounter(),
0N/A THREAD);
0N/A }
0N/A Handle protection_domain (THREAD, JNIHandles::resolve(pd));
0N/A klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
0N/A protection_domain, &st,
0N/A verify != 0,
0N/A CHECK_NULL);
0N/A
0N/A if (TraceClassResolution && k != NULL) {
0N/A trace_class_resolution(k);
0N/A }
0N/A
0N/A return (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
0N/A}
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
0N/A JVMWrapper2("JVM_DefineClass %s", name);
0N/A
0N/A return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, true, THREAD);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
0N/A JVMWrapper2("JVM_DefineClassWithSource %s", name);
0N/A
0N/A return jvm_define_class_common(env, name, loader, buf, len, pd, source, true, THREAD);
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jclass, JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name,
0N/A jobject loader, const jbyte *buf,
0N/A jsize len, jobject pd,
1666N/A const char *source, jboolean verify))
1666N/A JVMWrapper2("JVM_DefineClassWithSourceCond %s", name);
1666N/A
1666N/A return jvm_define_class_common(env, name, loader, buf, len, pd, source, verify, THREAD);
1666N/AJVM_END
1666N/A
1666N/AJVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name))
1666N/A JVMWrapper("JVM_FindLoadedClass");
1666N/A ResourceMark rm(THREAD);
1666N/A
1666N/A Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
1666N/A Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
1666N/A
1666N/A const char* str = java_lang_String::as_utf8_string(string());
1666N/A // Sanity check, don't expect null
1666N/A if (str == NULL) return NULL;
1666N/A
1666N/A const int str_len = (int)strlen(str);
1666N/A if (str_len > Symbol::max_length()) {
1666N/A // It's impossible to create this class; the name cannot fit
1666N/A // into the constant pool.
1666N/A return NULL;
1666N/A }
1666N/A TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL);
1666N/A
1666N/A // Security Note:
1666N/A // The Java level wrapper will perform the necessary security check allowing
1666N/A // us to pass the NULL as the initiating class loader.
1666N/A Handle h_loader(THREAD, JNIHandles::resolve(loader));
1666N/A if (UsePerfData) {
1666N/A is_lock_held_by_thread(h_loader,
1666N/A ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
1666N/A THREAD);
1666N/A }
1666N/A
1666N/A klassOop k = SystemDictionary::find_instance_or_array_klass(klass_name,
1666N/A h_loader,
1666N/A Handle(),
1666N/A CHECK_NULL);
1666N/A
1666N/A return (k == NULL) ? NULL :
1666N/A (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror());
1666N/AJVM_END
1666N/A
1666N/A
1666N/A// Reflection support //////////////////////////////////////////////////////////////////////////////
1666N/A
1666N/AJVM_ENTRY(jstring, JVM_GetClassName(JNIEnv *env, jclass cls))
1666N/A assert (cls != NULL, "illegal class");
1666N/A JVMWrapper("JVM_GetClassName");
1666N/A JvmtiVMObjectAllocEventCollector oam;
1666N/A ResourceMark rm(THREAD);
1666N/A const char* name;
1666N/A if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
1666N/A name = type2name(java_lang_Class::primitive_type(JNIHandles::resolve(cls)));
1666N/A } else {
246N/A // Consider caching interned string in Klass
246N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
1172N/A assert(k->is_klass(), "just checking");
0N/A name = Klass::cast(k)->external_name();
0N/A }
0N/A oop result = StringTable::intern((char*) name, CHECK_NULL);
0N/A return (jstring) JNIHandles::make_local(env, result);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassInterfaces");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A oop mirror = JNIHandles::resolve_non_null(cls);
0N/A
0N/A // Special handling for primitive objects
1172N/A if (java_lang_Class::is_primitive(mirror)) {
0N/A // Primitive objects does not have any interfaces
0N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
0N/A return (jobjectArray) JNIHandles::make_local(env, r);
248N/A }
0N/A
0N/A KlassHandle klass(thread, java_lang_Class::as_klassOop(mirror));
17N/A // Figure size of result array
17N/A int size;
17N/A if (klass->oop_is_instance()) {
0N/A size = instanceKlass::cast(klass())->local_interfaces()->length();
0N/A } else {
0N/A assert(klass->oop_is_objArray() || klass->oop_is_typeArray(), "Illegal mirror klass");
0N/A size = 2;
0N/A }
0N/A
248N/A // Allocate result array
0N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), size, CHECK_NULL);
248N/A objArrayHandle result (THREAD, r);
0N/A // Fill in result
0N/A if (klass->oop_is_instance()) {
0N/A // Regular instance klass, fill in all local interfaces
0N/A for (int index = 0; index < size; index++) {
0N/A klassOop k = klassOop(instanceKlass::cast(klass())->local_interfaces()->obj_at(index));
0N/A result->obj_at_put(index, Klass::cast(k)->java_mirror());
0N/A }
0N/A } else {
17N/A // All arrays implement java.lang.Cloneable and java.io.Serializable
17N/A result->obj_at_put(0, Klass::cast(SystemDictionary::Cloneable_klass())->java_mirror());
17N/A result->obj_at_put(1, Klass::cast(SystemDictionary::Serializable_klass())->java_mirror());
17N/A }
17N/A return (jobjectArray) JNIHandles::make_local(env, result());
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jobject, JVM_GetClassLoader(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassLoader");
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
0N/A return NULL;
0N/A }
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A oop loader = Klass::cast(k)->class_loader();
0N/A return JNIHandles::make_local(env, loader);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_IsInterface");
0N/A oop mirror = JNIHandles::resolve_non_null(cls);
0N/A if (java_lang_Class::is_primitive(mirror)) {
0N/A return JNI_FALSE;
0N/A }
17N/A klassOop k = java_lang_Class::as_klassOop(mirror);
17N/A jboolean result = Klass::cast(k)->is_interface();
17N/A assert(!result || Klass::cast(k)->oop_is_instance(),
17N/A "all interfaces are instance types");
0N/A // The compiler intrinsic for isInterface tests the
0N/A // Klass::_access_flags bits in the same way.
0N/A return result;
0N/AJVM_END
1172N/A
0N/A
1172N/AJVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassSigners");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
0N/A // There are no signers for primitive types
0N/A return NULL;
0N/A }
0N/A
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A objArrayOop signers = NULL;
17N/A if (Klass::cast(k)->oop_is_instance()) {
17N/A signers = instanceKlass::cast(k)->signers();
17N/A }
17N/A
0N/A // If there are no signers set in the class, or if the class
0N/A // is an array, return NULL.
0N/A if (signers == NULL) return NULL;
0N/A
0N/A // copy of the signers array
0N/A klassOop element = objArrayKlass::cast(signers->klass())->element_klass();
0N/A objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
0N/A for (int index = 0; index < signers->length(); index++) {
0N/A signers_copy->obj_at_put(index, signers->obj_at(index));
0N/A }
0N/A
0N/A // return the copy
17N/A return (jobjectArray) JNIHandles::make_local(env, signers_copy);
17N/AJVM_END
17N/A
0N/A
0N/AJVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers))
0N/A JVMWrapper("JVM_SetClassSigners");
0N/A if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
0N/A // This call is ignored for primitive types and arrays.
0N/A // Signers are only set once, ClassLoader.java, and thus shouldn't
0N/A // be called with an array. Only the bootstrap loader creates arrays.
248N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A if (Klass::cast(k)->oop_is_instance()) {
0N/A instanceKlass::cast(k)->set_signers(objArrayOop(JNIHandles::resolve(signers)));
0N/A }
0N/A }
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetProtectionDomain");
0N/A if (JNIHandles::resolve(cls) == NULL) {
17N/A THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
17N/A }
17N/A
17N/A if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
17N/A // Primitive types does not have a protection domain.
0N/A return NULL;
0N/A }
0N/A
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
0N/A return (jobject) JNIHandles::make_local(env, Klass::cast(k)->protection_domain());
0N/AJVM_END
0N/A
0N/A
0N/A// Obsolete since 1.2 (Class.setProtectionDomain removed), although
0N/A// still defined in core libraries as of 1.5.
0N/AJVM_ENTRY(void, JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain))
0N/A JVMWrapper("JVM_SetProtectionDomain");
0N/A if (JNIHandles::resolve(cls) == NULL) {
0N/A THROW(vmSymbols::java_lang_NullPointerException());
0N/A }
0N/A if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
0N/A // Call is ignored for primitive types
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
0N/A
0N/A // cls won't be an array, as this called only from ClassLoader.defineClass
37N/A if (Klass::cast(k)->oop_is_instance()) {
37N/A oop pd = JNIHandles::resolve(protection_domain);
37N/A assert(pd == NULL || pd->is_oop(), "just checking");
37N/A instanceKlass::cast(k)->set_protection_domain(pd);
37N/A }
37N/A }
37N/AJVM_END
37N/A
37N/A
37N/AJVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))
37N/A JVMWrapper("JVM_DoPrivileged");
37N/A
37N/A if (action == NULL) {
37N/A THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action");
37N/A }
37N/A
37N/A // Stack allocated list of privileged stack elements
37N/A PrivilegedElement pi;
37N/A
37N/A // Check that action object understands "Object run()"
37N/A Handle object (THREAD, JNIHandles::resolve(action));
0N/A
0N/A // get run() method
0N/A methodOop m_oop = Klass::cast(object->klass())->uncached_lookup_method(
0N/A vmSymbols::run_method_name(),
0N/A vmSymbols::void_object_signature());
0N/A methodHandle m (THREAD, m_oop);
0N/A if (m.is_null() || !m->is_method() || !methodOop(m())->is_public() || methodOop(m())->is_static()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
0N/A }
0N/A
0N/A // Compute the frame initiating the do privileged operation and setup the privileged stack
0N/A vframeStream vfst(thread);
0N/A vfst.security_get_caller_frame(1);
0N/A
0N/A if (!vfst.at_end()) {
0N/A pi.initialize(&vfst, JNIHandles::resolve(context), thread->privileged_stack_top(), CHECK_NULL);
0N/A thread->set_privileged_stack_top(&pi);
0N/A }
0N/A
17N/A
17N/A // invoke the Object run() in the action object. We cannot use call_interface here, since the static type
17N/A // is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction
17N/A Handle pending_exception;
17N/A JavaValue result(T_OBJECT);
17N/A JavaCallArguments args(object);
0N/A JavaCalls::call(&result, m, &args, THREAD);
0N/A
0N/A // done with action, remove ourselves from the list
1172N/A if (!vfst.at_end()) {
0N/A assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element");
1172N/A thread->set_privileged_stack_top(thread->privileged_stack_top()->next());
0N/A }
0N/A
0N/A if (HAS_PENDING_EXCEPTION) {
0N/A pending_exception = Handle(THREAD, PENDING_EXCEPTION);
0N/A CLEAR_PENDING_EXCEPTION;
0N/A
0N/A if ( pending_exception->is_a(SystemDictionary::Exception_klass()) &&
17N/A !pending_exception->is_a(SystemDictionary::RuntimeException_klass())) {
17N/A // Throw a java.security.PrivilegedActionException(Exception e) exception
17N/A JavaCallArguments args(pending_exception);
17N/A THROW_ARG_0(vmSymbols::java_security_PrivilegedActionException(),
17N/A vmSymbols::exception_void_signature(),
17N/A &args);
0N/A }
0N/A }
0N/A
0N/A if (pending_exception.not_null()) THROW_OOP_0(pending_exception());
0N/A return JNIHandles::make_local(env, (oop) result.get_jobject());
0N/AJVM_END
0N/A
0N/A
0N/A// Returns the inherited_access_control_context field of the running thread.
0N/AJVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetInheritedAccessControlContext");
0N/A oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj());
0N/A return JNIHandles::make_local(env, result);
0N/AJVM_END
0N/A
0N/Aclass RegisterArrayForGC {
0N/A private:
0N/A JavaThread *_thread;
0N/A public:
0N/A RegisterArrayForGC(JavaThread *thread, GrowableArray<oop>* array) {
1666N/A _thread = thread;
0N/A _thread->register_array_for_gc(array);
0N/A }
0N/A
0N/A ~RegisterArrayForGC() {
0N/A _thread->register_array_for_gc(NULL);
0N/A }
1666N/A};
0N/A
1666N/A
1666N/AJVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls))
1666N/A JVMWrapper("JVM_GetStackAccessControlContext");
1666N/A if (!UsePrivilegedStack) return NULL;
1666N/A
1666N/A ResourceMark rm(THREAD);
1666N/A GrowableArray<oop>* local_array = new GrowableArray<oop>(12);
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A
0N/A // count the protection domains on the execution stack. We collapse
0N/A // duplicate consecutive protection domains into a single one, as
0N/A // well as stopping when we hit a privileged frame.
0N/A
0N/A // Use vframeStream to iterate through Java frames
0N/A vframeStream vfst(thread);
0N/A
0N/A oop previous_protection_domain = NULL;
0N/A Handle privileged_context(thread, NULL);
0N/A bool is_privileged = false;
0N/A oop protection_domain = NULL;
0N/A
0N/A for(; !vfst.at_end(); vfst.next()) {
0N/A // get method of frame
0N/A methodOop method = vfst.method();
0N/A intptr_t* frame_id = vfst.frame_id();
0N/A
0N/A // check the privileged frames to see if we have a match
0N/A if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) {
0N/A // this frame is privileged
0N/A is_privileged = true;
0N/A privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
0N/A protection_domain = thread->privileged_stack_top()->protection_domain();
0N/A } else {
0N/A protection_domain = instanceKlass::cast(method->method_holder())->protection_domain();
0N/A }
0N/A
0N/A if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
0N/A local_array->push(protection_domain);
0N/A previous_protection_domain = protection_domain;
0N/A }
0N/A
0N/A if (is_privileged) break;
0N/A }
0N/A
0N/A
0N/A // either all the domains on the stack were system domains, or
0N/A // we had a privileged system domain
0N/A if (local_array->is_empty()) {
0N/A if (is_privileged && privileged_context.is_null()) return NULL;
0N/A
0N/A oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
0N/A return JNIHandles::make_local(env, result);
0N/A }
0N/A
0N/A // the resource area must be registered in case of a gc
0N/A RegisterArrayForGC ragc(thread, local_array);
0N/A objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(),
0N/A local_array->length(), CHECK_NULL);
0N/A objArrayHandle h_context(thread, context);
0N/A for (int index = 0; index < local_array->length(); index++) {
0N/A h_context->obj_at_put(index, local_array->at(index));
0N/A }
0N/A
0N/A oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
0N/A
0N/A return JNIHandles::make_local(env, result);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_IsArrayClass");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A return (k != NULL) && Klass::cast(k)->oop_is_javaArray() ? true : false;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_IsPrimitiveClass");
0N/A oop mirror = JNIHandles::resolve_non_null(cls);
0N/A return (jboolean) java_lang_Class::is_primitive(mirror);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_GetComponentType(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetComponentType");
0N/A oop mirror = JNIHandles::resolve_non_null(cls);
0N/A oop result = Reflection::array_component_type(mirror, CHECK_NULL);
0N/A return (jclass) JNIHandles::make_local(env, result);
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassModifiers");
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
0N/A // Primitive type
0N/A return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
0N/A }
0N/A
0N/A Klass* k = Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)));
0N/A debug_only(int computed_modifiers = k->compute_modifier_flags(CHECK_0));
0N/A assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK");
0N/A return k->modifier_flags();
0N/AJVM_END
0N/A
0N/A
0N/A// Inner class reflection ///////////////////////////////////////////////////////////////////////////////
0N/A
0N/AJVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass))
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A // ofClass is a reference to a java_lang_Class object. The mirror object
0N/A // of an instanceKlass
0N/A
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
0N/A ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) {
0N/A oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
0N/A return (jobjectArray)JNIHandles::make_local(env, result);
0N/A }
0N/A
0N/A instanceKlassHandle k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
0N/A InnerClassesIterator iter(k);
0N/A
0N/A if (iter.length() == 0) {
0N/A // Neither an inner nor outer class
0N/A oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
0N/A return (jobjectArray)JNIHandles::make_local(env, result);
0N/A }
0N/A
0N/A // find inner class info
0N/A constantPoolHandle cp(thread, k->constants());
0N/A int length = iter.length();
0N/A
0N/A // Allocate temp. result array
0N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL);
0N/A objArrayHandle result (THREAD, r);
0N/A int members = 0;
0N/A
0N/A for (; !iter.done(); iter.next()) {
0N/A int ioff = iter.inner_class_info_index();
0N/A int ooff = iter.outer_class_info_index();
0N/A
0N/A if (ioff != 0 && ooff != 0) {
0N/A // Check to see if the name matches the class we're looking for
0N/A // before attempting to find the class.
0N/A if (cp->klass_name_at_matches(k, ooff)) {
0N/A klassOop outer_klass = cp->klass_at(ooff, CHECK_NULL);
0N/A if (outer_klass == k()) {
0N/A klassOop ik = cp->klass_at(ioff, CHECK_NULL);
0N/A instanceKlassHandle inner_klass (THREAD, ik);
0N/A
0N/A // Throws an exception if outer klass has not declared k as
0N/A // an inner klass
0N/A Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
0N/A
0N/A result->obj_at_put(members, inner_klass->java_mirror());
0N/A members++;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (members != length) {
0N/A // Return array of right length
0N/A objArrayOop res = oopFactory::new_objArray(SystemDictionary::Class_klass(), members, CHECK_NULL);
0N/A for(int i = 0; i < members; i++) {
0N/A res->obj_at_put(i, result->obj_at(i));
0N/A }
0N/A return (jobjectArray)JNIHandles::make_local(env, res);
0N/A }
0N/A
0N/A return (jobjectArray)JNIHandles::make_local(env, result());
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
1485N/A{
1485N/A // ofClass is a reference to a java_lang_Class object.
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
0N/A ! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) {
0N/A return NULL;
0N/A }
0N/A
1522N/A bool inner_is_member = false;
0N/A klassOop outer_klass
1522N/A = instanceKlass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass))
1522N/A )->compute_enclosing_class(&inner_is_member, CHECK_NULL);
1522N/A if (outer_klass == NULL) return NULL; // already a top-level class
1522N/A if (!inner_is_member) return NULL; // an anonymous class (inside a method)
1522N/A return (jclass) JNIHandles::make_local(env, Klass::cast(outer_klass)->java_mirror());
1522N/A}
1522N/AJVM_END
1522N/A
1522N/A// should be in instanceKlass.cpp, but is here for historical reasons
1522N/AklassOop instanceKlass::compute_enclosing_class_impl(instanceKlassHandle k,
0N/A bool* inner_is_member,
1522N/A TRAPS) {
1522N/A Thread* thread = THREAD;
989N/A InnerClassesIterator iter(k);
989N/A if (iter.length() == 0) {
0N/A // No inner class info => no declaring class
0N/A return NULL;
0N/A }
0N/A
0N/A constantPoolHandle i_cp(thread, k->constants());
0N/A
0N/A bool found = false;
0N/A klassOop ok;
0N/A instanceKlassHandle outer_klass;
0N/A *inner_is_member = false;
0N/A
0N/A // Find inner_klass attribute
0N/A for (; !iter.done() && !found; iter.next()) {
0N/A int ioff = iter.inner_class_info_index();
0N/A int ooff = iter.outer_class_info_index();
0N/A int noff = iter.inner_name_index();
0N/A if (ioff != 0) {
0N/A // Check to see if the name matches the class we're looking for
0N/A // before attempting to find the class.
0N/A if (i_cp->klass_name_at_matches(k, ioff)) {
0N/A klassOop inner_klass = i_cp->klass_at(ioff, CHECK_NULL);
0N/A found = (k() == inner_klass);
0N/A if (found && ooff != 0) {
0N/A ok = i_cp->klass_at(ooff, CHECK_NULL);
0N/A outer_klass = instanceKlassHandle(thread, ok);
0N/A *inner_is_member = true;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (found && outer_klass.is_null()) {
0N/A // It may be anonymous; try for that.
0N/A int encl_method_class_idx = k->enclosing_method_class_index();
0N/A if (encl_method_class_idx != 0) {
0N/A ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL);
0N/A outer_klass = instanceKlassHandle(thread, ok);
0N/A *inner_is_member = false;
0N/A }
0N/A }
0N/A
0N/A // If no inner class attribute found for this class.
0N/A if (outer_klass.is_null()) return NULL;
0N/A
0N/A // Throws an exception if outer klass has not declared k as an inner klass
0N/A // We need evidence that each klass knows about the other, or else
0N/A // the system could allow a spoof of an inner class to gain access rights.
0N/A Reflection::check_for_inner_class(outer_klass, k, *inner_is_member, CHECK_NULL);
0N/A return outer_klass();
0N/A}
0N/A
0N/AJVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls))
0N/A assert (cls != NULL, "illegal class");
0N/A JVMWrapper("JVM_GetClassSignature");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A ResourceMark rm(THREAD);
0N/A // Return null for arrays and primatives
0N/A if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
0N/A if (Klass::cast(k)->oop_is_instance()) {
0N/A Symbol* sym = instanceKlass::cast(k)->generic_signature();
0N/A if (sym == NULL) return NULL;
0N/A Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
0N/A return (jstring) JNIHandles::make_local(env, str());
0N/A }
0N/A }
0N/A return NULL;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
0N/A assert (cls != NULL, "illegal class");
0N/A JVMWrapper("JVM_GetClassAnnotations");
0N/A ResourceMark rm(THREAD);
0N/A // Return null for arrays and primitives
0N/A if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve(cls));
0N/A if (Klass::cast(k)->oop_is_instance()) {
0N/A return (jbyteArray) JNIHandles::make_local(env,
0N/A instanceKlass::cast(k)->class_annotations());
0N/A }
0N/A }
0N/A return NULL;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field))
0N/A assert(field != NULL, "illegal field");
0N/A JVMWrapper("JVM_GetFieldAnnotations");
0N/A
0N/A // some of this code was adapted from from jni_FromReflectedField
0N/A
0N/A // field is a handle to a java.lang.reflect.Field object
0N/A oop reflected = JNIHandles::resolve_non_null(field);
0N/A oop mirror = java_lang_reflect_Field::clazz(reflected);
0N/A klassOop k = java_lang_Class::as_klassOop(mirror);
0N/A int slot = java_lang_reflect_Field::slot(reflected);
0N/A int modifiers = java_lang_reflect_Field::modifiers(reflected);
0N/A
0N/A fieldDescriptor fd;
0N/A KlassHandle kh(THREAD, k);
0N/A intptr_t offset = instanceKlass::cast(kh())->field_offset(slot);
0N/A
0N/A if (modifiers & JVM_ACC_STATIC) {
0N/A // for static fields we only look in the current class
0N/A if (!instanceKlass::cast(kh())->find_local_field_from_offset(offset,
0N/A true, &fd)) {
0N/A assert(false, "cannot find static field");
0N/A return NULL; // robustness
0N/A }
0N/A } else {
0N/A // for instance fields we start with the current class and work
0N/A // our way up through the superclass chain
0N/A if (!instanceKlass::cast(kh())->find_field_from_offset(offset, false,
0N/A &fd)) {
0N/A assert(false, "cannot find instance field");
0N/A return NULL; // robustness
0N/A }
0N/A }
0N/A
0N/A return (jbyteArray) JNIHandles::make_local(env, fd.annotations());
0N/AJVM_END
0N/A
0N/A
0N/Astatic methodOop jvm_get_method_common(jobject method, TRAPS) {
0N/A // some of this code was adapted from from jni_FromReflectedMethod
0N/A
0N/A oop reflected = JNIHandles::resolve_non_null(method);
0N/A oop mirror = NULL;
0N/A int slot = 0;
0N/A
0N/A if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) {
0N/A mirror = java_lang_reflect_Constructor::clazz(reflected);
0N/A slot = java_lang_reflect_Constructor::slot(reflected);
0N/A } else {
0N/A assert(reflected->klass() == SystemDictionary::reflect_Method_klass(),
0N/A "wrong type");
0N/A mirror = java_lang_reflect_Method::clazz(reflected);
0N/A slot = java_lang_reflect_Method::slot(reflected);
0N/A }
0N/A klassOop k = java_lang_Class::as_klassOop(mirror);
0N/A
0N/A KlassHandle kh(THREAD, k);
0N/A methodOop m = instanceKlass::cast(kh())->method_with_idnum(slot);
0N/A if (m == NULL) {
0N/A assert(false, "cannot find method");
0N/A return NULL; // robustness
0N/A }
0N/A
0N/A return m;
0N/A}
0N/A
0N/A
0N/AJVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method))
0N/A JVMWrapper("JVM_GetMethodAnnotations");
0N/A
0N/A // method is a handle to a java.lang.reflect.Method object
0N/A methodOop m = jvm_get_method_common(method, CHECK_NULL);
0N/A return (jbyteArray) JNIHandles::make_local(env, m->annotations());
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method))
0N/A JVMWrapper("JVM_GetMethodDefaultAnnotationValue");
0N/A
0N/A // method is a handle to a java.lang.reflect.Method object
0N/A methodOop m = jvm_get_method_common(method, CHECK_NULL);
0N/A return (jbyteArray) JNIHandles::make_local(env, m->annotation_default());
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method))
0N/A JVMWrapper("JVM_GetMethodParameterAnnotations");
0N/A
0N/A // method is a handle to a java.lang.reflect.Method object
0N/A methodOop m = jvm_get_method_common(method, CHECK_NULL);
0N/A return (jbyteArray) JNIHandles::make_local(env, m->parameter_annotations());
0N/AJVM_END
0N/A
0N/A
0N/A// New (JDK 1.4) reflection implementation /////////////////////////////////////
0N/A
0N/AJVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
0N/A{
0N/A JVMWrapper("JVM_GetClassDeclaredFields");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A
0N/A // Exclude primitive types and array types
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
0N/A Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
0N/A // Return empty array
0N/A oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL);
0N/A return (jobjectArray) JNIHandles::make_local(env, res);
0N/A }
0N/A
0N/A instanceKlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
0N/A constantPoolHandle cp(THREAD, k->constants());
0N/A
0N/A // Ensure class is linked
0N/A k->link_class(CHECK_NULL);
0N/A
0N/A // 4496456 We need to filter out java.lang.Throwable.backtrace
0N/A bool skip_backtrace = false;
0N/A
0N/A // Allocate result
0N/A int num_fields;
0N/A
0N/A if (publicOnly) {
0N/A num_fields = 0;
0N/A for (JavaFieldStream fs(k()); !fs.done(); fs.next()) {
0N/A if (fs.access_flags().is_public()) ++num_fields;
0N/A }
0N/A } else {
0N/A num_fields = k->java_fields_count();
0N/A
605N/A if (k() == SystemDictionary::Throwable_klass()) {
0N/A num_fields--;
0N/A skip_backtrace = true;
0N/A }
0N/A }
0N/A
0N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
605N/A objArrayHandle result (THREAD, r);
0N/A
0N/A int out_idx = 0;
0N/A fieldDescriptor fd;
0N/A for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
0N/A if (skip_backtrace) {
0N/A // 4496456 skip java.lang.Throwable.backtrace
0N/A int offset = fs.offset();
0N/A if (offset == java_lang_Throwable::get_backtrace_offset()) continue;
0N/A }
0N/A
0N/A if (!publicOnly || fs.access_flags().is_public()) {
605N/A fd.initialize(k(), fs.index());
0N/A oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL);
0N/A result->obj_at_put(out_idx, field);
0N/A ++out_idx;
0N/A }
827N/A }
0N/A assert(out_idx == num_fields, "just checking");
0N/A return (jobjectArray) JNIHandles::make_local(env, result());
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
605N/A{
0N/A JVMWrapper("JVM_GetClassDeclaredMethods");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A
0N/A // Exclude primitive types and array types
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
0N/A || Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
0N/A // Return empty array
605N/A oop res = oopFactory::new_objArray(SystemDictionary::reflect_Method_klass(), 0, CHECK_NULL);
0N/A return (jobjectArray) JNIHandles::make_local(env, res);
0N/A }
0N/A
0N/A instanceKlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
0N/A
0N/A // Ensure class is linked
0N/A k->link_class(CHECK_NULL);
0N/A
0N/A objArrayHandle methods (THREAD, k->methods());
0N/A int methods_length = methods->length();
0N/A int num_methods = 0;
0N/A
0N/A int i;
0N/A for (i = 0; i < methods_length; i++) {
0N/A methodHandle method(THREAD, (methodOop) methods->obj_at(i));
0N/A if (!method->is_initializer()) {
0N/A if (!publicOnly || method->is_public()) {
0N/A ++num_methods;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Allocate result
0N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Method_klass(), num_methods, CHECK_NULL);
0N/A objArrayHandle result (THREAD, r);
0N/A
0N/A int out_idx = 0;
0N/A for (i = 0; i < methods_length; i++) {
0N/A methodHandle method(THREAD, (methodOop) methods->obj_at(i));
0N/A if (!method->is_initializer()) {
0N/A if (!publicOnly || method->is_public()) {
0N/A oop m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL);
0N/A result->obj_at_put(out_idx, m);
0N/A ++out_idx;
0N/A }
0N/A }
0N/A }
0N/A assert(out_idx == num_methods, "just checking");
0N/A return (jobjectArray) JNIHandles::make_local(env, result());
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
0N/A{
0N/A JVMWrapper("JVM_GetClassDeclaredConstructors");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A
0N/A // Exclude primitive types and array types
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
0N/A || Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
0N/A // Return empty array
0N/A oop res = oopFactory::new_objArray(SystemDictionary::reflect_Constructor_klass(), 0 , CHECK_NULL);
0N/A return (jobjectArray) JNIHandles::make_local(env, res);
0N/A }
0N/A
0N/A instanceKlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)));
0N/A
0N/A // Ensure class is linked
0N/A k->link_class(CHECK_NULL);
0N/A
0N/A objArrayHandle methods (THREAD, k->methods());
0N/A int methods_length = methods->length();
0N/A int num_constructors = 0;
0N/A
0N/A int i;
0N/A for (i = 0; i < methods_length; i++) {
0N/A methodHandle method(THREAD, (methodOop) methods->obj_at(i));
0N/A if (method->is_initializer() && !method->is_static()) {
0N/A if (!publicOnly || method->is_public()) {
0N/A ++num_constructors;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Allocate result
0N/A objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Constructor_klass(), num_constructors, CHECK_NULL);
0N/A objArrayHandle result(THREAD, r);
0N/A
0N/A int out_idx = 0;
0N/A for (i = 0; i < methods_length; i++) {
0N/A methodHandle method(THREAD, (methodOop) methods->obj_at(i));
0N/A if (method->is_initializer() && !method->is_static()) {
0N/A if (!publicOnly || method->is_public()) {
0N/A oop m = Reflection::new_constructor(method, CHECK_NULL);
0N/A result->obj_at_put(out_idx, m);
0N/A ++out_idx;
0N/A }
0N/A }
0N/A }
0N/A assert(out_idx == num_constructors, "just checking");
0N/A return (jobjectArray) JNIHandles::make_local(env, result());
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls))
0N/A{
0N/A JVMWrapper("JVM_GetClassAccessFlags");
0N/A if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
0N/A // Primitive type
0N/A return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
0N/A }
0N/A
0N/A Klass* k = Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)));
0N/A return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS;
0N/A}
0N/AJVM_END
0N/A
0N/A
0N/A// Constant pool access //////////////////////////////////////////////////////////
0N/A
0N/AJVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls))
0N/A{
0N/A JVMWrapper("JVM_GetClassConstantPool");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A
0N/A // Return null for primitives and arrays
0N/A if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A if (Klass::cast(k)->oop_is_instance()) {
0N/A instanceKlassHandle k_h(THREAD, k);
0N/A Handle jcp = sun_reflect_ConstantPool::create(CHECK_NULL);
0N/A sun_reflect_ConstantPool::set_cp_oop(jcp(), k_h->constants());
0N/A return JNIHandles::make_local(jcp());
0N/A }
0N/A }
0N/A return NULL;
0N/A}
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetSize");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A return cp->length();
0N/A}
0N/AJVM_END
0N/A
0N/A
0N/Astatic void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
0N/A if (!cp->is_within_bounds(index)) {
0N/A THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
0N/A }
0N/A}
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetClassAt");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_klass() && !tag.is_unresolved_klass()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A klassOop k = cp->klass_at(index, CHECK_NULL);
0N/A return (jclass) JNIHandles::make_local(k->java_mirror());
0N/A}
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_klass() && !tag.is_unresolved_klass()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A klassOop k = constantPoolOopDesc::klass_at_if_loaded(cp, index);
0N/A if (k == NULL) return NULL;
0N/A return (jclass) JNIHandles::make_local(k->java_mirror());
0N/A}
0N/AJVM_END
0N/A
0N/Astatic jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_method() && !tag.is_interface_method()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A int klass_ref = cp->uncached_klass_ref_index_at(index);
0N/A klassOop k_o;
0N/A if (force_resolution) {
0N/A k_o = cp->klass_at(klass_ref, CHECK_NULL);
0N/A } else {
0N/A k_o = constantPoolOopDesc::klass_at_if_loaded(cp, klass_ref);
0N/A if (k_o == NULL) return NULL;
0N/A }
0N/A instanceKlassHandle k(THREAD, k_o);
0N/A Symbol* name = cp->uncached_name_ref_at(index);
0N/A Symbol* sig = cp->uncached_signature_ref_at(index);
0N/A methodHandle m (THREAD, k->find_method(name, sig));
0N/A if (m.is_null()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
0N/A }
0N/A oop method;
0N/A if (!m->is_initializer() || m->is_static()) {
0N/A method = Reflection::new_method(m, true, true, CHECK_NULL);
0N/A } else {
0N/A method = Reflection::new_constructor(m, CHECK_NULL);
0N/A }
0N/A return JNIHandles::make_local(method);
0N/A}
0N/A
0N/AJVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetMethodAt");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
0N/A return res;
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);
0N/A return res;
0N/A}
0N/AJVM_END
0N/A
0N/Astatic jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_field()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A int klass_ref = cp->uncached_klass_ref_index_at(index);
0N/A klassOop k_o;
0N/A if (force_resolution) {
0N/A k_o = cp->klass_at(klass_ref, CHECK_NULL);
0N/A } else {
0N/A k_o = constantPoolOopDesc::klass_at_if_loaded(cp, klass_ref);
0N/A if (k_o == NULL) return NULL;
0N/A }
0N/A instanceKlassHandle k(THREAD, k_o);
0N/A Symbol* name = cp->uncached_name_ref_at(index);
0N/A Symbol* sig = cp->uncached_signature_ref_at(index);
0N/A fieldDescriptor fd;
0N/A klassOop target_klass = k->find_field(name, sig, &fd);
0N/A if (target_klass == NULL) {
0N/A THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class");
0N/A }
0N/A oop field = Reflection::new_field(&fd, true, CHECK_NULL);
0N/A return JNIHandles::make_local(field);
0N/A}
0N/A
0N/AJVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetFieldAt");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A jobject res = get_field_at_helper(cp, index, true, CHECK_NULL);
0N/A return res;
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetFieldAtIfLoaded");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A jobject res = get_field_at_helper(cp, index, false, CHECK_NULL);
0N/A return res;
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetMemberRefInfoAt");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_field_or_method()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A int klass_ref = cp->uncached_klass_ref_index_at(index);
0N/A Symbol* klass_name = cp->klass_name_at(klass_ref);
0N/A Symbol* member_name = cp->uncached_name_ref_at(index);
0N/A Symbol* member_sig = cp->uncached_signature_ref_at(index);
0N/A objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), 3, CHECK_NULL);
0N/A objArrayHandle dest(THREAD, dest_o);
0N/A Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL);
0N/A dest->obj_at_put(0, str());
0N/A str = java_lang_String::create_from_symbol(member_name, CHECK_NULL);
0N/A dest->obj_at_put(1, str());
0N/A str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL);
0N/A dest->obj_at_put(2, str());
0N/A return (jobjectArray) JNIHandles::make_local(dest());
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetIntAt");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_0);
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_int()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A return cp->int_at(index);
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetLongAt");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_(0L));
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_long()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A return cp->long_at(index);
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetFloatAt");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_(0.0f));
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_float()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A return cp->float_at(index);
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetDoubleAt");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_(0.0));
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_double()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A return cp->double_at(index);
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetStringAt");
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_string() && !tag.is_unresolved_string()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A oop str = cp->string_at(index, CHECK_NULL);
0N/A return (jstring) JNIHandles::make_local(str);
0N/A}
0N/AJVM_END
0N/A
0N/AJVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index))
0N/A{
0N/A JVMWrapper("JVM_ConstantPoolGetUTF8At");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
0N/A bounds_check(cp, index, CHECK_NULL);
0N/A constantTag tag = cp->tag_at(index);
0N/A if (!tag.is_symbol()) {
0N/A THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
0N/A }
0N/A Symbol* sym = cp->symbol_at(index);
0N/A Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
0N/A return (jstring) JNIHandles::make_local(str());
0N/A}
0N/AJVM_END
0N/A
0N/A
0N/A// Assertion support. //////////////////////////////////////////////////////////
0N/A
0N/AJVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls))
0N/A JVMWrapper("JVM_DesiredAssertionStatus");
0N/A assert(cls != NULL, "bad class");
0N/A
0N/A oop r = JNIHandles::resolve(cls);
0N/A assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed");
0N/A if (java_lang_Class::is_primitive(r)) return false;
0N/A
0N/A klassOop k = java_lang_Class::as_klassOop(r);
0N/A assert(Klass::cast(k)->oop_is_instance(), "must be an instance klass");
0N/A if (! Klass::cast(k)->oop_is_instance()) return false;
0N/A
0N/A ResourceMark rm(THREAD);
0N/A const char* name = Klass::cast(k)->name()->as_C_string();
0N/A bool system_class = Klass::cast(k)->class_loader() == NULL;
0N/A return JavaAssertions::enabled(name, system_class);
0N/A
0N/AJVM_END
0N/A
0N/A
0N/A// Return a new AssertionStatusDirectives object with the fields filled in with
0N/A// command-line assertion arguments (i.e., -ea, -da).
0N/AJVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
0N/A JVMWrapper("JVM_AssertionStatusDirectives");
0N/A JvmtiVMObjectAllocEventCollector oam;
0N/A oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
0N/A return JNIHandles::make_local(env, asd);
0N/AJVM_END
0N/A
0N/A// Verification ////////////////////////////////////////////////////////////////////////////////
0N/A
0N/A// Reflection for the verifier /////////////////////////////////////////////////////////////////
0N/A
0N/A// RedefineClasses support: bug 6214132 caused verification to fail.
0N/A// All functions from this section should call the jvmtiThreadSate function:
0N/A// klassOop class_to_verify_considering_redefinition(klassOop klass).
0N/A// The function returns a klassOop of the _scratch_class if the verifier
0N/A// was invoked in the middle of the class redefinition.
0N/A// Otherwise it returns its argument value which is the _the_class klassOop.
0N/A// Please, refer to the description in the jvmtiThreadSate.hpp.
0N/A
0N/AJVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassNameUTF");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A return Klass::cast(k)->name()->as_utf8();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
0N/A JVMWrapper("JVM_GetClassCPTypes");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A // types will have length zero if this is not an instanceKlass
0N/A // (length is determined by call to JVM_GetClassCPEntriesCount)
0N/A if (Klass::cast(k)->oop_is_instance()) {
0N/A constantPoolOop cp = instanceKlass::cast(k)->constants();
0N/A for (int index = cp->length() - 1; index >= 0; index--) {
0N/A constantTag tag = cp->tag_at(index);
0N/A types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class :
0N/A (tag.is_unresolved_string()) ? JVM_CONSTANT_String : tag.value();
0N/A }
0N/A }
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassCPEntriesCount");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A if (!Klass::cast(k)->oop_is_instance())
0N/A return 0;
0N/A return instanceKlass::cast(k)->constants()->length();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassFieldsCount");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A if (!Klass::cast(k)->oop_is_instance())
0N/A return 0;
0N/A return instanceKlass::cast(k)->java_fields_count();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls))
0N/A JVMWrapper("JVM_GetClassMethodsCount");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A if (!Klass::cast(k)->oop_is_instance())
0N/A return 0;
0N/A return instanceKlass::cast(k)->methods()->length();
1213N/AJVM_END
1213N/A
1213N/A
1213N/A// The following methods, used for the verifier, are never called with
1213N/A// array klasses, so a direct cast to instanceKlass is safe.
0N/A// Typically, these methods are called in a loop with bounds determined
0N/A// by the results of JVM_GetClass{Fields,Methods}Count, which return
0N/A// zero for arrays.
0N/AJVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
0N/A JVMWrapper("JVM_GetMethodIxExceptionIndexes");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A int length = methodOop(method)->checked_exceptions_length();
0N/A if (length > 0) {
0N/A CheckedExceptionElement* table= methodOop(method)->checked_exceptions_start();
0N/A for (int i = 0; i < length; i++) {
0N/A exceptions[i] = table[i].class_cp_index;
0N/A }
0N/A }
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index))
0N/A JVMWrapper("JVM_GetMethodIxExceptionsCount");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->checked_exceptions_length();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
0N/A JVMWrapper("JVM_GetMethodIxByteCode");
248N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
248N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
248N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
254N/A memcpy(code, methodOop(method)->code_base(), methodOop(method)->code_size());
254N/AJVM_END
248N/A
248N/A
248N/AJVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
248N/A JVMWrapper("JVM_GetMethodIxByteCodeLength");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->code_size();
0N/AJVM_END
254N/A
254N/A
0N/AJVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
0N/A JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A ExceptionTable extable((methodOop(method)));
0N/A entry->start_pc = extable.start_pc(entry_index);
0N/A entry->end_pc = extable.end_pc(entry_index);
0N/A entry->handler_pc = extable.handler_pc(entry_index);
0N/A entry->catchType = extable.catch_type_index(entry_index);
0N/AJVM_END
0N/A
0N/A
254N/AJVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
254N/A JVMWrapper("JVM_GetMethodIxExceptionTableLength");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->exception_table_length();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
0N/A JVMWrapper("JVM_GetMethodIxModifiers");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
254N/AJVM_END
254N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
0N/A JVMWrapper("JVM_GetFieldIxModifiers");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A return instanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index))
0N/A JVMWrapper("JVM_GetMethodIxLocalsCount");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->max_locals();
726N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
0N/A JVMWrapper("JVM_GetMethodIxArgsSize");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->size_of_parameters();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
0N/A JVMWrapper("JVM_GetMethodIxMaxStack");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->max_stack();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
0N/A JVMWrapper("JVM_IsConstructorIx");
0N/A ResourceMark rm(THREAD);
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->name() == vmSymbols::object_initializer_name();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
0N/A JVMWrapper("JVM_GetMethodIxIxUTF");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->name()->as_utf8();
0N/AJVM_END
0N/A
0N/A
0N/AJVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
0N/A JVMWrapper("JVM_GetMethodIxSignatureUTF");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A oop method = instanceKlass::cast(k)->methods()->obj_at(method_index);
0N/A return methodOop(method)->signature()->as_utf8();
0N/AJVM_END
0N/A
0N/A/**
0N/A * All of these JVM_GetCP-xxx methods are used by the old verifier to
0N/A * read entries in the constant pool. Since the old verifier always
0N/A * works on a copy of the code, it will not see any rewriting that
0N/A * may possibly occur in the middle of verification. So it is important
0N/A * that nothing it calls tries to use the cpCache instead of the raw
0N/A * constant pool, so we must use cp->uncached_x methods when appropriate.
0N/A */
0N/AJVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index))
0N/A JVMWrapper("JVM_GetCPFieldNameUTF");
0N/A klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
0N/A k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
0N/A constantPoolOop cp = instanceKlass::cast(k)->constants();
0N/A switch (cp->tag_at(cp_index).value()) {
0N/A case JVM_CONSTANT_Fieldref:
0N/A return cp->uncached_name_ref_at(cp_index)->as_utf8();
222N/A default:
0N/A fatal("JVM_GetCPFieldNameUTF: illegal constant");
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
JVM_END
JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index))
JVMWrapper("JVM_GetCPMethodNameUTF");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
switch (cp->tag_at(cp_index).value()) {
case JVM_CONSTANT_InterfaceMethodref:
case JVM_CONSTANT_Methodref:
case JVM_CONSTANT_NameAndType: // for invokedynamic
return cp->uncached_name_ref_at(cp_index)->as_utf8();
default:
fatal("JVM_GetCPMethodNameUTF: illegal constant");
}
ShouldNotReachHere();
return NULL;
JVM_END
JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
JVMWrapper("JVM_GetCPMethodSignatureUTF");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
switch (cp->tag_at(cp_index).value()) {
case JVM_CONSTANT_InterfaceMethodref:
case JVM_CONSTANT_Methodref:
case JVM_CONSTANT_NameAndType: // for invokedynamic
return cp->uncached_signature_ref_at(cp_index)->as_utf8();
default:
fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
}
ShouldNotReachHere();
return NULL;
JVM_END
JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
JVMWrapper("JVM_GetCPFieldSignatureUTF");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
switch (cp->tag_at(cp_index).value()) {
case JVM_CONSTANT_Fieldref:
return cp->uncached_signature_ref_at(cp_index)->as_utf8();
default:
fatal("JVM_GetCPFieldSignatureUTF: illegal constant");
}
ShouldNotReachHere();
return NULL;
JVM_END
JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
JVMWrapper("JVM_GetCPClassNameUTF");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
Symbol* classname = cp->klass_name_at(cp_index);
return classname->as_utf8();
JVM_END
JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
JVMWrapper("JVM_GetCPFieldClassNameUTF");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
switch (cp->tag_at(cp_index).value()) {
case JVM_CONSTANT_Fieldref: {
int class_index = cp->uncached_klass_ref_index_at(cp_index);
Symbol* classname = cp->klass_name_at(class_index);
return classname->as_utf8();
}
default:
fatal("JVM_GetCPFieldClassNameUTF: illegal constant");
}
ShouldNotReachHere();
return NULL;
JVM_END
JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
JVMWrapper("JVM_GetCPMethodClassNameUTF");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
switch (cp->tag_at(cp_index).value()) {
case JVM_CONSTANT_Methodref:
case JVM_CONSTANT_InterfaceMethodref: {
int class_index = cp->uncached_klass_ref_index_at(cp_index);
Symbol* classname = cp->klass_name_at(class_index);
return classname->as_utf8();
}
default:
fatal("JVM_GetCPMethodClassNameUTF: illegal constant");
}
ShouldNotReachHere();
return NULL;
JVM_END
JVM_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
JVMWrapper("JVM_GetCPFieldModifiers");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
klassOop k_called = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(called_cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
constantPoolOop cp_called = instanceKlass::cast(k_called)->constants();
switch (cp->tag_at(cp_index).value()) {
case JVM_CONSTANT_Fieldref: {
Symbol* name = cp->uncached_name_ref_at(cp_index);
Symbol* signature = cp->uncached_signature_ref_at(cp_index);
for (JavaFieldStream fs(k_called); !fs.done(); fs.next()) {
if (fs.name() == name && fs.signature() == signature) {
return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS;
}
}
return -1;
}
default:
fatal("JVM_GetCPFieldModifiers: illegal constant");
}
ShouldNotReachHere();
return 0;
JVM_END
JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
JVMWrapper("JVM_GetCPMethodModifiers");
klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls));
klassOop k_called = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(called_cls));
k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
constantPoolOop cp = instanceKlass::cast(k)->constants();
switch (cp->tag_at(cp_index).value()) {
case JVM_CONSTANT_Methodref:
case JVM_CONSTANT_InterfaceMethodref: {
Symbol* name = cp->uncached_name_ref_at(cp_index);
Symbol* signature = cp->uncached_signature_ref_at(cp_index);
objArrayOop methods = instanceKlass::cast(k_called)->methods();
int methods_count = methods->length();
for (int i = 0; i < methods_count; i++) {
methodOop method = methodOop(methods->obj_at(i));
if (method->name() == name && method->signature() == signature) {
return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
}
}
return -1;
}
default:
fatal("JVM_GetCPMethodModifiers: illegal constant");
}
ShouldNotReachHere();
return 0;
JVM_END
// Misc //////////////////////////////////////////////////////////////////////////////////////////////
JVM_LEAF(void, JVM_ReleaseUTF(const char *utf))
// So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything
JVM_END
JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2))
JVMWrapper("JVM_IsSameClassPackage");
oop class1_mirror = JNIHandles::resolve_non_null(class1);
oop class2_mirror = JNIHandles::resolve_non_null(class2);
klassOop klass1 = java_lang_Class::as_klassOop(class1_mirror);
klassOop klass2 = java_lang_Class::as_klassOop(class2_mirror);
return (jboolean) Reflection::is_same_class_package(klass1, klass2);
JVM_END
// IO functions ////////////////////////////////////////////////////////////////////////////////////////
JVM_LEAF(jint, JVM_Open(const char *fname, jint flags, jint mode))
JVMWrapper2("JVM_Open (%s)", fname);
//%note jvm_r6
int result = os::open(fname, flags, mode);
if (result >= 0) {
return result;
} else {
switch(errno) {
case EEXIST:
return JVM_EEXIST;
default:
return -1;
}
}
JVM_END
JVM_LEAF(jint, JVM_Close(jint fd))
JVMWrapper2("JVM_Close (0x%x)", fd);
//%note jvm_r6
return os::close(fd);
JVM_END
JVM_LEAF(jint, JVM_Read(jint fd, char *buf, jint nbytes))
JVMWrapper2("JVM_Read (0x%x)", fd);
//%note jvm_r6
return (jint)os::restartable_read(fd, buf, nbytes);
JVM_END
JVM_LEAF(jint, JVM_Write(jint fd, char *buf, jint nbytes))
JVMWrapper2("JVM_Write (0x%x)", fd);
//%note jvm_r6
return (jint)os::write(fd, buf, nbytes);
JVM_END
JVM_LEAF(jint, JVM_Available(jint fd, jlong *pbytes))
JVMWrapper2("JVM_Available (0x%x)", fd);
//%note jvm_r6
return os::available(fd, pbytes);
JVM_END
JVM_LEAF(jlong, JVM_Lseek(jint fd, jlong offset, jint whence))
JVMWrapper4("JVM_Lseek (0x%x, %Ld, %d)", fd, offset, whence);
//%note jvm_r6
return os::lseek(fd, offset, whence);
JVM_END
JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
JVMWrapper3("JVM_SetLength (0x%x, %Ld)", fd, length);
return os::ftruncate(fd, length);
JVM_END
JVM_LEAF(jint, JVM_Sync(jint fd))
JVMWrapper2("JVM_Sync (0x%x)", fd);
//%note jvm_r6
return os::fsync(fd);
JVM_END
// Printing support //////////////////////////////////////////////////
extern "C" {
int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
// see bug 4399518, 4417214
if ((intptr_t)count <= 0) return -1;
return vsnprintf(str, count, fmt, args);
}
int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
va_list args;
int len;
va_start(args, fmt);
len = jio_vsnprintf(str, count, fmt, args);
va_end(args);
return len;
}
int jio_fprintf(FILE* f, const char *fmt, ...) {
int len;
va_list args;
va_start(args, fmt);
len = jio_vfprintf(f, fmt, args);
va_end(args);
return len;
}
int jio_vfprintf(FILE* f, const char *fmt, va_list args) {
if (Arguments::vfprintf_hook() != NULL) {
return Arguments::vfprintf_hook()(f, fmt, args);
} else {
return vfprintf(f, fmt, args);
}
}
JNIEXPORT int jio_printf(const char *fmt, ...) {
int len;
va_list args;
va_start(args, fmt);
len = jio_vfprintf(defaultStream::output_stream(), fmt, args);
va_end(args);
return len;
}
// HotSpot specific jio method
void jio_print(const char* s) {
// Try to make this function as atomic as possible.
if (Arguments::vfprintf_hook() != NULL) {
jio_fprintf(defaultStream::output_stream(), "%s", s);
} else {
// Make an unused local variable to avoid warning from gcc 4.x compiler.
size_t count = ::write(defaultStream::output_fd(), s, (int)strlen(s));
}
}
} // Extern C
// java.lang.Thread //////////////////////////////////////////////////////////////////////////////
// In most of the JVM Thread support functions we need to be sure to lock the Threads_lock
// to prevent the target thread from exiting after we have a pointer to the C++ Thread or
// OSThread objects. The exception to this rule is when the target object is the thread
// doing the operation, in which case we know that the thread won't exit until the
// operation is done (all exits being voluntary). There are a few cases where it is
// rather silly to do operations on yourself, like resuming yourself or asking whether
// you are alive. While these can still happen, they are not subject to deadlocks if
// the lock is held while the operation occurs (this is not the case for suspend, for
// instance), and are very unlikely. Because IsAlive needs to be fast and its
// implementation is local to this file, we always lock Threads_lock for that one.
static void thread_entry(JavaThread* thread, TRAPS) {
HandleMark hm(THREAD);
Handle obj(THREAD, thread->threadObj());
JavaValue result(T_VOID);
JavaCalls::call_virtual(&result,
obj,
KlassHandle(THREAD, SystemDictionary::Thread_klass()),
vmSymbols::run_method_name(),
vmSymbols::void_method_signature(),
THREAD);
}
JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread))
JVMWrapper("JVM_StartThread");
JavaThread *native_thread = NULL;
// We cannot hold the Threads_lock when we throw an exception,
// due to rank ordering issues. Example: we might need to grab the
// Heap_lock while we construct the exception.
bool throw_illegal_thread_state = false;
// We must release the Threads_lock before we can post a jvmti event
// in Thread::start.
{
// Ensure that the C++ Thread and OSThread structures aren't freed before
// we operate.
MutexLocker mu(Threads_lock);
// Since JDK 5 the java.lang.Thread threadStatus is used to prevent
// re-starting an already started thread, so we should usually find
// that the JavaThread is null. However for a JNI attached thread
// there is a small window between the Thread object being created
// (with its JavaThread set) and the update to its threadStatus, so we
// have to check for this
if (java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) {
throw_illegal_thread_state = true;
} else {
// We could also check the stillborn flag to see if this thread was already stopped, but
// for historical reasons we let the thread detect that itself when it starts running
jlong size =
java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread));
// Allocate the C++ Thread structure and create the native thread. The
// stack size retrieved from java is signed, but the constructor takes
// size_t (an unsigned type), so avoid passing negative values which would
// result in really large stacks.
size_t sz = size > 0 ? (size_t) size : 0;
native_thread = new JavaThread(&thread_entry, sz);
// At this point it may be possible that no osthread was created for the
// JavaThread due to lack of memory. Check for this situation and throw
// an exception if necessary. Eventually we may want to change this so
// that we only grab the lock if the thread was created successfully -
// then we can also do this check and throw the exception in the
// JavaThread constructor.
if (native_thread->osthread() != NULL) {
// Note: the current thread is not being used within "prepare".
native_thread->prepare(jthread);
}
}
}
if (throw_illegal_thread_state) {
THROW(vmSymbols::java_lang_IllegalThreadStateException());
}
assert(native_thread != NULL, "Starting null thread?");
if (native_thread->osthread() == NULL) {
// No one should hold a reference to the 'native_thread'.
delete native_thread;
if (JvmtiExport::should_post_resource_exhausted()) {
JvmtiExport::post_resource_exhausted(
JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS,
"unable to create new native thread");
}
THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
"unable to create new native thread");
}
Thread::start(native_thread);
JVM_END
// JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints
// before the quasi-asynchronous exception is delivered. This is a little obtrusive,
// but is thought to be reliable and simple. In the case, where the receiver is the
// same thread as the sender, no safepoint is needed.
JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable))
JVMWrapper("JVM_StopThread");
oop java_throwable = JNIHandles::resolve(throwable);
if (java_throwable == NULL) {
THROW(vmSymbols::java_lang_NullPointerException());
}
oop java_thread = JNIHandles::resolve_non_null(jthread);
JavaThread* receiver = java_lang_Thread::thread(java_thread);
Events::log_exception(JavaThread::current(),
"JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]",
receiver, (address)java_thread, throwable);
// First check if thread is alive
if (receiver != NULL) {
// Check if exception is getting thrown at self (use oop equality, since the
// target object might exit)
if (java_thread == thread->threadObj()) {
THROW_OOP(java_throwable);
} else {
// Enques a VM_Operation to stop all threads and then deliver the exception...
Thread::send_async_exception(java_thread, JNIHandles::resolve(throwable));
}
}
else {
// Either:
// - target thread has not been started before being stopped, or
// - target thread already terminated
// We could read the threadStatus to determine which case it is
// but that is overkill as it doesn't matter. We must set the
// stillborn flag for the first case, and if the thread has already
// exited setting this flag has no affect
java_lang_Thread::set_stillborn(java_thread);
}
JVM_END
JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread))
JVMWrapper("JVM_IsThreadAlive");
oop thread_oop = JNIHandles::resolve_non_null(jthread);
return java_lang_Thread::is_alive(thread_oop);
JVM_END
JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread))
JVMWrapper("JVM_SuspendThread");
oop java_thread = JNIHandles::resolve_non_null(jthread);
JavaThread* receiver = java_lang_Thread::thread(java_thread);
if (receiver != NULL) {
// thread has run and has not exited (still on threads list)
{
MutexLockerEx ml(receiver->SR_lock(), Mutex::_no_safepoint_check_flag);
if (receiver->is_external_suspend()) {
// Don't allow nested external suspend requests. We can't return
// an error from this interface so just ignore the problem.
return;
}
if (receiver->is_exiting()) { // thread is in the process of exiting
return;
}
receiver->set_external_suspend();
}
// java_suspend() will catch threads in the process of exiting
// and will ignore them.
receiver->java_suspend();
// It would be nice to have the following assertion in all the
// time, but it is possible for a racing resume request to have
// resumed this thread right after we suspended it. Temporarily
// enable this assertion if you are chasing a different kind of
// bug.
//
// assert(java_lang_Thread::thread(receiver->threadObj()) == NULL ||
// receiver->is_being_ext_suspended(), "thread is not suspended");
}
JVM_END
JVM_ENTRY(void, JVM_ResumeThread(JNIEnv* env, jobject jthread))
JVMWrapper("JVM_ResumeThread");
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate.
// We need to *always* get the threads lock here, since this operation cannot be allowed during
// a safepoint. The safepoint code relies on suspending a thread to examine its state. If other
// threads randomly resumes threads, then a thread might not be suspended when the safepoint code
// looks at it.
MutexLocker ml(Threads_lock);
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
if (thr != NULL) {
// the thread has run and is not in the process of exiting
thr->java_resume();
}
JVM_END
JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio))
JVMWrapper("JVM_SetThreadPriority");
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate
MutexLocker ml(Threads_lock);
oop java_thread = JNIHandles::resolve_non_null(jthread);
java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio);
JavaThread* thr = java_lang_Thread::thread(java_thread);
if (thr != NULL) { // Thread not yet started; priority pushed down when it is
Thread::set_priority(thr, (ThreadPriority)prio);
}
JVM_END
JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
JVMWrapper("JVM_Yield");
if (os::dont_yield()) return;
#ifndef USDT2
HS_DTRACE_PROBE0(hotspot, thread__yield);
#else /* USDT2 */
HOTSPOT_THREAD_YIELD();
#endif /* USDT2 */
// When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
// Critical for similar threading behaviour
if (ConvertYieldToSleep) {
os::sleep(thread, MinSleepInterval, false);
} else {
os::yield();
}
JVM_END
JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
JVMWrapper("JVM_Sleep");
if (millis < 0) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
}
if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
}
// Save current thread state and restore it at the end of this block.
// And set new thread state to SLEEPING.
JavaThreadSleepState jtss(thread);
#ifndef USDT2
HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
#else /* USDT2 */
HOTSPOT_THREAD_SLEEP_BEGIN(
millis);
#endif /* USDT2 */
if (millis == 0) {
// When ConvertSleepToYield is on, this matches the classic VM implementation of
// JVM_Sleep. Critical for similar threading behaviour (Win32)
// It appears that in certain GUI contexts, it may be beneficial to do a short sleep
// for SOLARIS
if (ConvertSleepToYield) {
os::yield();
} else {
ThreadState old_state = thread->osthread()->get_state();
thread->osthread()->set_state(SLEEPING);
os::sleep(thread, MinSleepInterval, false);
thread->osthread()->set_state(old_state);
}
} else {
ThreadState old_state = thread->osthread()->get_state();
thread->osthread()->set_state(SLEEPING);
if (os::sleep(thread, millis, true) == OS_INTRPT) {
// An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
// us while we were sleeping. We do not overwrite those.
if (!HAS_PENDING_EXCEPTION) {
#ifndef USDT2
HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
#else /* USDT2 */
HOTSPOT_THREAD_SLEEP_END(
1);
#endif /* USDT2 */
// TODO-FIXME: THROW_MSG returns which means we will not call set_state()
// to properly restore the thread state. That's likely wrong.
THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
}
}
thread->osthread()->set_state(old_state);
}
#ifndef USDT2
HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
#else /* USDT2 */
HOTSPOT_THREAD_SLEEP_END(
0);
#endif /* USDT2 */
JVM_END
JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
JVMWrapper("JVM_CurrentThread");
oop jthread = thread->threadObj();
assert (thread != NULL, "no current thread!");
return JNIHandles::make_local(env, jthread);
JVM_END
JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
JVMWrapper("JVM_CountStackFrames");
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate
oop java_thread = JNIHandles::resolve_non_null(jthread);
bool throw_illegal_thread_state = false;
int count = 0;
{
MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
// We need to re-resolve the java_thread, since a GC might have happened during the
// acquire of the lock
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
if (thr == NULL) {
// do nothing
} else if(! thr->is_external_suspend() || ! thr->frame_anchor()->walkable()) {
// Check whether this java thread has been suspended already. If not, throws
// IllegalThreadStateException. We defer to throw that exception until
// Threads_lock is released since loading exception class has to leave VM.
// The correct way to test a thread is actually suspended is
// wait_for_ext_suspend_completion(), but we can't call that while holding
// the Threads_lock. The above tests are sufficient for our purposes
// provided the walkability of the stack is stable - which it isn't
// 100% but close enough for most practical purposes.
throw_illegal_thread_state = true;
} else {
// Count all java activation, i.e., number of vframes
for(vframeStream vfst(thr); !vfst.at_end(); vfst.next()) {
// Native frames are not counted
if (!vfst.method()->is_native()) count++;
}
}
}
if (throw_illegal_thread_state) {
THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(),
"this thread is not suspended");
}
return count;
JVM_END
// Consider: A better way to implement JVM_Interrupt() is to acquire
// Threads_lock to resolve the jthread into a Thread pointer, fetch
// Thread->platformevent, Thread->native_thr, Thread->parker, etc.,
// drop Threads_lock, and the perform the unpark() and thr_kill() operations
// outside the critical section. Threads_lock is hot so we want to minimize
// the hold-time. A cleaner interface would be to decompose interrupt into
// two steps. The 1st phase, performed under Threads_lock, would return
// a closure that'd be invoked after Threads_lock was dropped.
// This tactic is safe as PlatformEvent and Parkers are type-stable (TSM) and
// admit spurious wakeups.
JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
JVMWrapper("JVM_Interrupt");
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate
oop java_thread = JNIHandles::resolve_non_null(jthread);
MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
// We need to re-resolve the java_thread, since a GC might have happened during the
// acquire of the lock
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
if (thr != NULL) {
Thread::interrupt(thr);
}
JVM_END
JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted))
JVMWrapper("JVM_IsInterrupted");
// Ensure that the C++ Thread and OSThread structures aren't freed before we operate
oop java_thread = JNIHandles::resolve_non_null(jthread);
MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
// We need to re-resolve the java_thread, since a GC might have happened during the
// acquire of the lock
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
if (thr == NULL) {
return JNI_FALSE;
} else {
return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
}
JVM_END
// Return true iff the current thread has locked the object passed in
JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
JVMWrapper("JVM_HoldsLock");
assert(THREAD->is_Java_thread(), "sanity check");
if (obj == NULL) {
THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
}
Handle h_obj(THREAD, JNIHandles::resolve(obj));
return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
JVM_END
JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
JVMWrapper("JVM_DumpAllStacks");
VM_PrintThreads op;
VMThread::execute(&op);
if (JvmtiExport::should_post_data_dump()) {
JvmtiExport::post_data_dump();
}
JVM_END
JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
JVMWrapper("JVM_SetNativeThreadName");
ResourceMark rm(THREAD);
oop java_thread = JNIHandles::resolve_non_null(jthread);
JavaThread* thr = java_lang_Thread::thread(java_thread);
// Thread naming only supported for the current thread, doesn't work for
// target threads.
if (Thread::current() == thr && !thr->has_attached_via_jni()) {
// we don't set the name of an attached thread to avoid stepping
// on other programs
const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
os::set_native_thread_name(thread_name);
}
JVM_END
// java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) {
assert(jthread->is_Java_thread(), "must be a Java thread");
if (jthread->privileged_stack_top() == NULL) return false;
if (jthread->privileged_stack_top()->frame_id() == vfst->frame_id()) {
oop loader = jthread->privileged_stack_top()->class_loader();
if (loader == NULL) return true;
bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
if (trusted) return true;
}
return false;
}
JVM_ENTRY(jclass, JVM_CurrentLoadedClass(JNIEnv *env))
JVMWrapper("JVM_CurrentLoadedClass");
ResourceMark rm(THREAD);
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
// if a method in a class in a trusted loader is in a doPrivileged, return NULL
bool trusted = is_trusted_frame(thread, &vfst);
if (trusted) return NULL;
methodOop m = vfst.method();
if (!m->is_native()) {
klassOop holder = m->method_holder();
oop loader = instanceKlass::cast(holder)->class_loader();
if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
return (jclass) JNIHandles::make_local(env, Klass::cast(holder)->java_mirror());
}
}
}
return NULL;
JVM_END
JVM_ENTRY(jobject, JVM_CurrentClassLoader(JNIEnv *env))
JVMWrapper("JVM_CurrentClassLoader");
ResourceMark rm(THREAD);
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
// if a method in a class in a trusted loader is in a doPrivileged, return NULL
bool trusted = is_trusted_frame(thread, &vfst);
if (trusted) return NULL;
methodOop m = vfst.method();
if (!m->is_native()) {
klassOop holder = m->method_holder();
assert(holder->is_klass(), "just checking");
oop loader = instanceKlass::cast(holder)->class_loader();
if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
return JNIHandles::make_local(env, loader);
}
}
}
return NULL;
JVM_END
// Utility object for collecting method holders walking down the stack
class KlassLink: public ResourceObj {
public:
KlassHandle klass;
KlassLink* next;
KlassLink(KlassHandle k) { klass = k; next = NULL; }
};
JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
JVMWrapper("JVM_GetClassContext");
ResourceMark rm(THREAD);
JvmtiVMObjectAllocEventCollector oam;
// Collect linked list of (handles to) method holders
KlassLink* first = NULL;
KlassLink* last = NULL;
int depth = 0;
for(vframeStream vfst(thread); !vfst.at_end(); vfst.security_get_caller_frame(1)) {
// Native frames are not returned
if (!vfst.method()->is_native()) {
klassOop holder = vfst.method()->method_holder();
assert(holder->is_klass(), "just checking");
depth++;
KlassLink* l = new KlassLink(KlassHandle(thread, holder));
if (first == NULL) {
first = last = l;
} else {
last->next = l;
last = l;
}
}
}
// Create result array of type [Ljava/lang/Class;
objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), depth, CHECK_NULL);
// Fill in mirrors corresponding to method holders
int index = 0;
while (first != NULL) {
result->obj_at_put(index++, Klass::cast(first->klass())->java_mirror());
first = first->next;
}
assert(index == depth, "just checking");
return (jobjectArray) JNIHandles::make_local(env, result);
JVM_END
JVM_ENTRY(jint, JVM_ClassDepth(JNIEnv *env, jstring name))
JVMWrapper("JVM_ClassDepth");
ResourceMark rm(THREAD);
Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
Handle class_name_str = java_lang_String::internalize_classname(h_name, CHECK_0);
const char* str = java_lang_String::as_utf8_string(class_name_str());
TempNewSymbol class_name_sym = SymbolTable::probe(str, (int)strlen(str));
if (class_name_sym == NULL) {
return -1;
}
int depth = 0;
for(vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
if (!vfst.method()->is_native()) {
klassOop holder = vfst.method()->method_holder();
assert(holder->is_klass(), "just checking");
if (instanceKlass::cast(holder)->name() == class_name_sym) {
return depth;
}
depth++;
}
}
return -1;
JVM_END
JVM_ENTRY(jint, JVM_ClassLoaderDepth(JNIEnv *env))
JVMWrapper("JVM_ClassLoaderDepth");
ResourceMark rm(THREAD);
int depth = 0;
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
// if a method in a class in a trusted loader is in a doPrivileged, return -1
bool trusted = is_trusted_frame(thread, &vfst);
if (trusted) return -1;
methodOop m = vfst.method();
if (!m->is_native()) {
klassOop holder = m->method_holder();
assert(holder->is_klass(), "just checking");
oop loader = instanceKlass::cast(holder)->class_loader();
if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
return depth;
}
depth++;
}
}
return -1;
JVM_END
// java.lang.Package ////////////////////////////////////////////////////////////////
JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name))
JVMWrapper("JVM_GetSystemPackage");
ResourceMark rm(THREAD);
JvmtiVMObjectAllocEventCollector oam;
char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
oop result = ClassLoader::get_system_package(str, CHECK_NULL);
return (jstring) JNIHandles::make_local(result);
JVM_END
JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env))
JVMWrapper("JVM_GetSystemPackages");
JvmtiVMObjectAllocEventCollector oam;
objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL);
return (jobjectArray) JNIHandles::make_local(result);
JVM_END
// ObjectInputStream ///////////////////////////////////////////////////////////////
bool force_verify_field_access(klassOop current_class, klassOop field_class, AccessFlags access, bool classloader_only) {
if (current_class == NULL) {
return true;
}
if ((current_class == field_class) || access.is_public()) {
return true;
}
if (access.is_protected()) {
// See if current_class is a subclass of field_class
if (Klass::cast(current_class)->is_subclass_of(field_class)) {
return true;
}
}
return (!access.is_private() && instanceKlass::cast(current_class)->is_same_class_package(field_class));
}
// JVM_AllocateNewObject and JVM_AllocateNewArray are unused as of 1.4
JVM_ENTRY(jobject, JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass))
JVMWrapper("JVM_AllocateNewObject");
JvmtiVMObjectAllocEventCollector oam;
// Receiver is not used
oop curr_mirror = JNIHandles::resolve_non_null(currClass);
oop init_mirror = JNIHandles::resolve_non_null(initClass);
// Cannot instantiate primitive types
if (java_lang_Class::is_primitive(curr_mirror) || java_lang_Class::is_primitive(init_mirror)) {
ResourceMark rm(THREAD);
THROW_0(vmSymbols::java_lang_InvalidClassException());
}
// Arrays not allowed here, must use JVM_AllocateNewArray
if (Klass::cast(java_lang_Class::as_klassOop(curr_mirror))->oop_is_javaArray() ||
Klass::cast(java_lang_Class::as_klassOop(init_mirror))->oop_is_javaArray()) {
ResourceMark rm(THREAD);
THROW_0(vmSymbols::java_lang_InvalidClassException());
}
instanceKlassHandle curr_klass (THREAD, java_lang_Class::as_klassOop(curr_mirror));
instanceKlassHandle init_klass (THREAD, java_lang_Class::as_klassOop(init_mirror));
assert(curr_klass->is_subclass_of(init_klass()), "just checking");
// Interfaces, abstract classes, and java.lang.Class classes cannot be instantiated directly.
curr_klass->check_valid_for_instantiation(false, CHECK_NULL);
// Make sure klass is initialized, since we are about to instantiate one of them.
curr_klass->initialize(CHECK_NULL);
methodHandle m (THREAD,
init_klass->find_method(vmSymbols::object_initializer_name(),
vmSymbols::void_method_signature()));
if (m.is_null()) {
ResourceMark rm(THREAD);
THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(),
methodOopDesc::name_and_sig_as_C_string(Klass::cast(init_klass()),
vmSymbols::object_initializer_name(),
vmSymbols::void_method_signature()));
}
if (curr_klass == init_klass && !m->is_public()) {
// Calling the constructor for class 'curr_klass'.
// Only allow calls to a public no-arg constructor.
// This path corresponds to creating an Externalizable object.
THROW_0(vmSymbols::java_lang_IllegalAccessException());
}
if (!force_verify_field_access(curr_klass(), init_klass(), m->access_flags(), false)) {
// subclass 'curr_klass' does not have access to no-arg constructor of 'initcb'
THROW_0(vmSymbols::java_lang_IllegalAccessException());
}
Handle obj = curr_klass->allocate_instance_handle(CHECK_NULL);
// Call constructor m. This might call a constructor higher up in the hierachy
JavaCalls::call_default_constructor(thread, m, obj, CHECK_NULL);
return JNIHandles::make_local(obj());
JVM_END
JVM_ENTRY(jobject, JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length))
JVMWrapper("JVM_AllocateNewArray");
JvmtiVMObjectAllocEventCollector oam;
oop mirror = JNIHandles::resolve_non_null(currClass);
if (java_lang_Class::is_primitive(mirror)) {
THROW_0(vmSymbols::java_lang_InvalidClassException());
}
klassOop k = java_lang_Class::as_klassOop(mirror);
oop result;
if (k->klass_part()->oop_is_typeArray()) {
// typeArray
result = typeArrayKlass::cast(k)->allocate(length, CHECK_NULL);
} else if (k->klass_part()->oop_is_objArray()) {
// objArray
objArrayKlassHandle oak(THREAD, k);
oak->initialize(CHECK_NULL); // make sure class is initialized (matches Classic VM behavior)
result = oak->allocate(length, CHECK_NULL);
} else {
THROW_0(vmSymbols::java_lang_InvalidClassException());
}
return JNIHandles::make_local(env, result);
JVM_END
// Return the first non-null class loader up the execution stack, or null
// if only code from the null class loader is on the stack.
JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env))
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
// UseNewReflection
vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection
klassOop holder = vfst.method()->method_holder();
oop loader = instanceKlass::cast(holder)->class_loader();
if (loader != NULL) {
return JNIHandles::make_local(env, loader);
}
}
return NULL;
JVM_END
// Load a class relative to the most recent class on the stack with a non-null
// classloader.
// This function has been deprecated and should not be considered part of the
// specified JVM interface.
JVM_ENTRY(jclass, JVM_LoadClass0(JNIEnv *env, jobject receiver,
jclass currClass, jstring currClassName))
JVMWrapper("JVM_LoadClass0");
// Receiver is not used
ResourceMark rm(THREAD);
// Class name argument is not guaranteed to be in internal format
Handle classname (THREAD, JNIHandles::resolve_non_null(currClassName));
Handle string = java_lang_String::internalize_classname(classname, CHECK_NULL);
const char* str = java_lang_String::as_utf8_string(string());
if (str == NULL || (int)strlen(str) > Symbol::max_length()) {
// It's impossible to create this class; the name cannot fit
// into the constant pool.
THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), str);
}
TempNewSymbol name = SymbolTable::new_symbol(str, CHECK_NULL);
Handle curr_klass (THREAD, JNIHandles::resolve(currClass));
// Find the most recent class on the stack with a non-null classloader
oop loader = NULL;
oop protection_domain = NULL;
if (curr_klass.is_null()) {
for (vframeStream vfst(thread);
!vfst.at_end() && loader == NULL;
vfst.next()) {
if (!vfst.method()->is_native()) {
klassOop holder = vfst.method()->method_holder();
loader = instanceKlass::cast(holder)->class_loader();
protection_domain = instanceKlass::cast(holder)->protection_domain();
}
}
} else {
klassOop curr_klass_oop = java_lang_Class::as_klassOop(curr_klass());
loader = instanceKlass::cast(curr_klass_oop)->class_loader();
protection_domain = instanceKlass::cast(curr_klass_oop)->protection_domain();
}
Handle h_loader(THREAD, loader);
Handle h_prot (THREAD, protection_domain);
jclass result = find_class_from_class_loader(env, name, true, h_loader, h_prot,
false, thread);
if (TraceClassResolution && result != NULL) {
trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result)));
}
return result;
JVM_END
// Array ///////////////////////////////////////////////////////////////////////////////////////////
// resolve array handle and check arguments
static inline arrayOop check_array(JNIEnv *env, jobject arr, bool type_array_only, TRAPS) {
if (arr == NULL) {
THROW_0(vmSymbols::java_lang_NullPointerException());
}
oop a = JNIHandles::resolve_non_null(arr);
if (!a->is_javaArray() || (type_array_only && !a->is_typeArray())) {
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array");
}
return arrayOop(a);
}
JVM_ENTRY(jint, JVM_GetArrayLength(JNIEnv *env, jobject arr))
JVMWrapper("JVM_GetArrayLength");
arrayOop a = check_array(env, arr, false, CHECK_0);
return a->length();
JVM_END
JVM_ENTRY(jobject, JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index))
JVMWrapper("JVM_Array_Get");
JvmtiVMObjectAllocEventCollector oam;
arrayOop a = check_array(env, arr, false, CHECK_NULL);
jvalue value;
BasicType type = Reflection::array_get(&value, a, index, CHECK_NULL);
oop box = Reflection::box(&value, type, CHECK_NULL);
return JNIHandles::make_local(env, box);
JVM_END
JVM_ENTRY(jvalue, JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode))
JVMWrapper("JVM_GetPrimitiveArrayElement");
jvalue value;
value.i = 0; // to initialize value before getting used in CHECK
arrayOop a = check_array(env, arr, true, CHECK_(value));
assert(a->is_typeArray(), "just checking");
BasicType type = Reflection::array_get(&value, a, index, CHECK_(value));
BasicType wide_type = (BasicType) wCode;
if (type != wide_type) {
Reflection::widen(&value, type, wide_type, CHECK_(value));
}
return value;
JVM_END
JVM_ENTRY(void, JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val))
JVMWrapper("JVM_SetArrayElement");
arrayOop a = check_array(env, arr, false, CHECK);
oop box = JNIHandles::resolve(val);
jvalue value;
value.i = 0; // to initialize value before getting used in CHECK
BasicType value_type;
if (a->is_objArray()) {
// Make sure we do no unbox e.g. java/lang/Integer instances when storing into an object array
value_type = Reflection::unbox_for_regular_object(box, &value);
} else {
value_type = Reflection::unbox_for_primitive(box, &value, CHECK);
}
Reflection::array_set(&value, a, index, value_type, CHECK);
JVM_END
JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode))
JVMWrapper("JVM_SetPrimitiveArrayElement");
arrayOop a = check_array(env, arr, true, CHECK);
assert(a->is_typeArray(), "just checking");
BasicType value_type = (BasicType) vCode;
Reflection::array_set(&v, a, index, value_type, CHECK);
JVM_END
JVM_ENTRY(jobject, JVM_NewArray(JNIEnv *env, jclass eltClass, jint length))
JVMWrapper("JVM_NewArray");
JvmtiVMObjectAllocEventCollector oam;
oop element_mirror = JNIHandles::resolve(eltClass);
oop result = Reflection::reflect_new_array(element_mirror, length, CHECK_NULL);
return JNIHandles::make_local(env, result);
JVM_END
JVM_ENTRY(jobject, JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim))
JVMWrapper("JVM_NewMultiArray");
JvmtiVMObjectAllocEventCollector oam;
arrayOop dim_array = check_array(env, dim, true, CHECK_NULL);
oop element_mirror = JNIHandles::resolve(eltClass);
assert(dim_array->is_typeArray(), "just checking");
oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL);
return JNIHandles::make_local(env, result);
JVM_END
// Networking library support ////////////////////////////////////////////////////////////////////
JVM_LEAF(jint, JVM_InitializeSocketLibrary())
JVMWrapper("JVM_InitializeSocketLibrary");
return 0;
JVM_END
JVM_LEAF(jint, JVM_Socket(jint domain, jint type, jint protocol))
JVMWrapper("JVM_Socket");
return os::socket(domain, type, protocol);
JVM_END
JVM_LEAF(jint, JVM_SocketClose(jint fd))
JVMWrapper2("JVM_SocketClose (0x%x)", fd);
//%note jvm_r6
return os::socket_close(fd);
JVM_END
JVM_LEAF(jint, JVM_SocketShutdown(jint fd, jint howto))
JVMWrapper2("JVM_SocketShutdown (0x%x)", fd);
//%note jvm_r6
return os::socket_shutdown(fd, howto);
JVM_END
JVM_LEAF(jint, JVM_Recv(jint fd, char *buf, jint nBytes, jint flags))
JVMWrapper2("JVM_Recv (0x%x)", fd);
//%note jvm_r6
return os::recv(fd, buf, (size_t)nBytes, (uint)flags);
JVM_END
JVM_LEAF(jint, JVM_Send(jint fd, char *buf, jint nBytes, jint flags))
JVMWrapper2("JVM_Send (0x%x)", fd);
//%note jvm_r6
return os::send(fd, buf, (size_t)nBytes, (uint)flags);
JVM_END
JVM_LEAF(jint, JVM_Timeout(int fd, long timeout))
JVMWrapper2("JVM_Timeout (0x%x)", fd);
//%note jvm_r6
return os::timeout(fd, timeout);
JVM_END
JVM_LEAF(jint, JVM_Listen(jint fd, jint count))
JVMWrapper2("JVM_Listen (0x%x)", fd);
//%note jvm_r6
return os::listen(fd, count);
JVM_END
JVM_LEAF(jint, JVM_Connect(jint fd, struct sockaddr *him, jint len))
JVMWrapper2("JVM_Connect (0x%x)", fd);
//%note jvm_r6
return os::connect(fd, him, (socklen_t)len);
JVM_END
JVM_LEAF(jint, JVM_Bind(jint fd, struct sockaddr *him, jint len))
JVMWrapper2("JVM_Bind (0x%x)", fd);
//%note jvm_r6
return os::bind(fd, him, (socklen_t)len);
JVM_END
JVM_LEAF(jint, JVM_Accept(jint fd, struct sockaddr *him, jint *len))
JVMWrapper2("JVM_Accept (0x%x)", fd);
//%note jvm_r6
socklen_t socklen = (socklen_t)(*len);
jint result = os::accept(fd, him, &socklen);
*len = (jint)socklen;
return result;
JVM_END
JVM_LEAF(jint, JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen))
JVMWrapper2("JVM_RecvFrom (0x%x)", fd);
//%note jvm_r6
socklen_t socklen = (socklen_t)(*fromlen);
jint result = os::recvfrom(fd, buf, (size_t)nBytes, (uint)flags, from, &socklen);
*fromlen = (int)socklen;
return result;
JVM_END
JVM_LEAF(jint, JVM_GetSockName(jint fd, struct sockaddr *him, int *len))
JVMWrapper2("JVM_GetSockName (0x%x)", fd);
//%note jvm_r6
socklen_t socklen = (socklen_t)(*len);
jint result = os::get_sock_name(fd, him, &socklen);
*len = (int)socklen;
return result;
JVM_END
JVM_LEAF(jint, JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen))
JVMWrapper2("JVM_SendTo (0x%x)", fd);
//%note jvm_r6
return os::sendto(fd, buf, (size_t)len, (uint)flags, to, (socklen_t)tolen);
JVM_END
JVM_LEAF(jint, JVM_SocketAvailable(jint fd, jint *pbytes))
JVMWrapper2("JVM_SocketAvailable (0x%x)", fd);
//%note jvm_r6
return os::socket_available(fd, pbytes);
JVM_END
JVM_LEAF(jint, JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen))
JVMWrapper2("JVM_GetSockOpt (0x%x)", fd);
//%note jvm_r6
socklen_t socklen = (socklen_t)(*optlen);
jint result = os::get_sock_opt(fd, level, optname, optval, &socklen);
*optlen = (int)socklen;
return result;
JVM_END
JVM_LEAF(jint, JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen))
JVMWrapper2("JVM_GetSockOpt (0x%x)", fd);
//%note jvm_r6
return os::set_sock_opt(fd, level, optname, optval, (socklen_t)optlen);
JVM_END
JVM_LEAF(int, JVM_GetHostName(char* name, int namelen))
JVMWrapper("JVM_GetHostName");
return os::get_host_name(name, namelen);
JVM_END
// Library support ///////////////////////////////////////////////////////////////////////////
JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name))
//%note jvm_ct
JVMWrapper2("JVM_LoadLibrary (%s)", name);
char ebuf[1024];
void *load_result;
{
ThreadToNativeFromVM ttnfvm(thread);
load_result = os::dll_load(name, ebuf, sizeof ebuf);
}
if (load_result == NULL) {
char msg[1024];
jio_snprintf(msg, sizeof msg, "%s: %s", name, ebuf);
// Since 'ebuf' may contain a string encoded using
// platform encoding scheme, we need to pass
// Exceptions::unsafe_to_utf8 to the new_exception method
// as the last argument. See bug 6367357.
Handle h_exception =
Exceptions::new_exception(thread,
vmSymbols::java_lang_UnsatisfiedLinkError(),
msg, Exceptions::unsafe_to_utf8);
THROW_HANDLE_0(h_exception);
}
return load_result;
JVM_END
JVM_LEAF(void, JVM_UnloadLibrary(void* handle))
JVMWrapper("JVM_UnloadLibrary");
os::dll_unload(handle);
JVM_END
JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
JVMWrapper2("JVM_FindLibraryEntry (%s)", name);
return os::dll_lookup(handle, name);
JVM_END
// Floating point support ////////////////////////////////////////////////////////////////////
JVM_LEAF(jboolean, JVM_IsNaN(jdouble a))
JVMWrapper("JVM_IsNaN");
return g_isnan(a);
JVM_END
// JNI version ///////////////////////////////////////////////////////////////////////////////
JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
JVMWrapper2("JVM_IsSupportedJNIVersion (%d)", version);
return Threads::is_supported_jni_version_including_1_1(version);
JVM_END
// String support ///////////////////////////////////////////////////////////////////////////
JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
JVMWrapper("JVM_InternString");
JvmtiVMObjectAllocEventCollector oam;
if (str == NULL) return NULL;
oop string = JNIHandles::resolve_non_null(str);
oop result = StringTable::intern(string, CHECK_NULL);
return (jstring) JNIHandles::make_local(env, result);
JVM_END
// Raw monitor support //////////////////////////////////////////////////////////////////////
// The lock routine below calls lock_without_safepoint_check in order to get a raw lock
// without interfering with the safepoint mechanism. The routines are not JVM_LEAF because
// they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check
// that only works with java threads.
JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorCreate");
return new Mutex(Mutex::native, "JVM_RawMonitorCreate");
}
JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorDestroy");
delete ((Mutex*) mon);
}
JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorEnter");
((Mutex*) mon)->jvm_raw_lock();
return 0;
}
JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
VM_Exit::block_if_vm_exited();
JVMWrapper("JVM_RawMonitorExit");
((Mutex*) mon)->jvm_raw_unlock();
}
// Support for Serialization
typedef jfloat (JNICALL *IntBitsToFloatFn )(JNIEnv* env, jclass cb, jint value);
typedef jdouble (JNICALL *LongBitsToDoubleFn)(JNIEnv* env, jclass cb, jlong value);
typedef jint (JNICALL *FloatToIntBitsFn )(JNIEnv* env, jclass cb, jfloat value);
typedef jlong (JNICALL *DoubleToLongBitsFn)(JNIEnv* env, jclass cb, jdouble value);
static IntBitsToFloatFn int_bits_to_float_fn = NULL;
static LongBitsToDoubleFn long_bits_to_double_fn = NULL;
static FloatToIntBitsFn float_to_int_bits_fn = NULL;
static DoubleToLongBitsFn double_to_long_bits_fn = NULL;
void initialize_converter_functions() {
if (JDK_Version::is_gte_jdk14x_version()) {
// These functions only exist for compatibility with 1.3.1 and earlier
return;
}
// called from universe_post_init()
assert(
int_bits_to_float_fn == NULL &&
long_bits_to_double_fn == NULL &&
float_to_int_bits_fn == NULL &&
double_to_long_bits_fn == NULL ,
"initialization done twice"
);
// initialize
int_bits_to_float_fn = CAST_TO_FN_PTR(IntBitsToFloatFn , NativeLookup::base_library_lookup("java/lang/Float" , "intBitsToFloat" , "(I)F"));
long_bits_to_double_fn = CAST_TO_FN_PTR(LongBitsToDoubleFn, NativeLookup::base_library_lookup("java/lang/Double", "longBitsToDouble", "(J)D"));
float_to_int_bits_fn = CAST_TO_FN_PTR(FloatToIntBitsFn , NativeLookup::base_library_lookup("java/lang/Float" , "floatToIntBits" , "(F)I"));
double_to_long_bits_fn = CAST_TO_FN_PTR(DoubleToLongBitsFn, NativeLookup::base_library_lookup("java/lang/Double", "doubleToLongBits", "(D)J"));
// verify
assert(
int_bits_to_float_fn != NULL &&
long_bits_to_double_fn != NULL &&
float_to_int_bits_fn != NULL &&
double_to_long_bits_fn != NULL ,
"initialization failed"
);
}
// Serialization
JVM_ENTRY(void, JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj,
jlongArray fieldIDs, jcharArray typecodes, jbyteArray data))
assert(!JDK_Version::is_gte_jdk14x_version(), "should only be used in 1.3.1 and earlier");
typeArrayOop tcodes = typeArrayOop(JNIHandles::resolve(typecodes));
typeArrayOop dbuf = typeArrayOop(JNIHandles::resolve(data));
typeArrayOop fids = typeArrayOop(JNIHandles::resolve(fieldIDs));
oop o = JNIHandles::resolve(obj);
if (o == NULL || fids == NULL || dbuf == NULL || tcodes == NULL) {
THROW(vmSymbols::java_lang_NullPointerException());
}
jsize nfids = fids->length();
if (nfids == 0) return;
if (tcodes->length() < nfids) {
THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
}
jsize off = 0;
/* loop through fields, setting values */
for (jsize i = 0; i < nfids; i++) {
jfieldID fid = (jfieldID)(intptr_t) fids->long_at(i);
int field_offset;
if (fid != NULL) {
// NULL is a legal value for fid, but retrieving the field offset
// trigger assertion in that case
field_offset = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid);
}
switch (tcodes->char_at(i)) {
case 'Z':
if (fid != NULL) {
jboolean val = (dbuf->byte_at(off) != 0) ? JNI_TRUE : JNI_FALSE;
o->bool_field_put(field_offset, val);
}
off++;
break;
case 'B':
if (fid != NULL) {
o->byte_field_put(field_offset, dbuf->byte_at(off));
}
off++;
break;
case 'C':
if (fid != NULL) {
jchar val = ((dbuf->byte_at(off + 0) & 0xFF) << 8)
+ ((dbuf->byte_at(off + 1) & 0xFF) << 0);
o->char_field_put(field_offset, val);
}
off += 2;
break;
case 'S':
if (fid != NULL) {
jshort val = ((dbuf->byte_at(off + 0) & 0xFF) << 8)
+ ((dbuf->byte_at(off + 1) & 0xFF) << 0);
o->short_field_put(field_offset, val);
}
off += 2;
break;
case 'I':
if (fid != NULL) {
jint ival = ((dbuf->byte_at(off + 0) & 0xFF) << 24)
+ ((dbuf->byte_at(off + 1) & 0xFF) << 16)
+ ((dbuf->byte_at(off + 2) & 0xFF) << 8)
+ ((dbuf->byte_at(off + 3) & 0xFF) << 0);
o->int_field_put(field_offset, ival);
}
off += 4;
break;
case 'F':
if (fid != NULL) {
jint ival = ((dbuf->byte_at(off + 0) & 0xFF) << 24)
+ ((dbuf->byte_at(off + 1) & 0xFF) << 16)
+ ((dbuf->byte_at(off + 2) & 0xFF) << 8)
+ ((dbuf->byte_at(off + 3) & 0xFF) << 0);
jfloat fval = (*int_bits_to_float_fn)(env, NULL, ival);
o->float_field_put(field_offset, fval);
}
off += 4;
break;
case 'J':
if (fid != NULL) {
jlong lval = (((jlong) dbuf->byte_at(off + 0) & 0xFF) << 56)
+ (((jlong) dbuf->byte_at(off + 1) & 0xFF) << 48)
+ (((jlong) dbuf->byte_at(off + 2) & 0xFF) << 40)
+ (((jlong) dbuf->byte_at(off + 3) & 0xFF) << 32)
+ (((jlong) dbuf->byte_at(off + 4) & 0xFF) << 24)
+ (((jlong) dbuf->byte_at(off + 5) & 0xFF) << 16)
+ (((jlong) dbuf->byte_at(off + 6) & 0xFF) << 8)
+ (((jlong) dbuf->byte_at(off + 7) & 0xFF) << 0);
o->long_field_put(field_offset, lval);
}
off += 8;
break;
case 'D':
if (fid != NULL) {
jlong lval = (((jlong) dbuf->byte_at(off + 0) & 0xFF) << 56)
+ (((jlong) dbuf->byte_at(off + 1) & 0xFF) << 48)
+ (((jlong) dbuf->byte_at(off + 2) & 0xFF) << 40)
+ (((jlong) dbuf->byte_at(off + 3) & 0xFF) << 32)
+ (((jlong) dbuf->byte_at(off + 4) & 0xFF) << 24)
+ (((jlong) dbuf->byte_at(off + 5) & 0xFF) << 16)
+ (((jlong) dbuf->byte_at(off + 6) & 0xFF) << 8)
+ (((jlong) dbuf->byte_at(off + 7) & 0xFF) << 0);
jdouble dval = (*long_bits_to_double_fn)(env, NULL, lval);
o->double_field_put(field_offset, dval);
}
off += 8;
break;
default:
// Illegal typecode
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "illegal typecode");
}
}
JVM_END
JVM_ENTRY(void, JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj,
jlongArray fieldIDs, jcharArray typecodes, jbyteArray data))
assert(!JDK_Version::is_gte_jdk14x_version(), "should only be used in 1.3.1 and earlier");
typeArrayOop tcodes = typeArrayOop(JNIHandles::resolve(typecodes));
typeArrayOop dbuf = typeArrayOop(JNIHandles::resolve(data));
typeArrayOop fids = typeArrayOop(JNIHandles::resolve(fieldIDs));
oop o = JNIHandles::resolve(obj);
if (o == NULL || fids == NULL || dbuf == NULL || tcodes == NULL) {
THROW(vmSymbols::java_lang_NullPointerException());
}
jsize nfids = fids->length();
if (nfids == 0) return;
if (tcodes->length() < nfids) {
THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
}
/* loop through fields, fetching values */
jsize off = 0;
for (jsize i = 0; i < nfids; i++) {
jfieldID fid = (jfieldID)(intptr_t) fids->long_at(i);
if (fid == NULL) {
THROW(vmSymbols::java_lang_NullPointerException());
}
int field_offset = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid);
switch (tcodes->char_at(i)) {
case 'Z':
{
jboolean val = o->bool_field(field_offset);
dbuf->byte_at_put(off++, (val != 0) ? 1 : 0);
}
break;
case 'B':
dbuf->byte_at_put(off++, o->byte_field(field_offset));
break;
case 'C':
{
jchar val = o->char_field(field_offset);
dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
}
break;
case 'S':
{
jshort val = o->short_field(field_offset);
dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
}
break;
case 'I':
{
jint val = o->int_field(field_offset);
dbuf->byte_at_put(off++, (val >> 24) & 0xFF);
dbuf->byte_at_put(off++, (val >> 16) & 0xFF);
dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
}
break;
case 'F':
{
jfloat fval = o->float_field(field_offset);
jint ival = (*float_to_int_bits_fn)(env, NULL, fval);
dbuf->byte_at_put(off++, (ival >> 24) & 0xFF);
dbuf->byte_at_put(off++, (ival >> 16) & 0xFF);
dbuf->byte_at_put(off++, (ival >> 8) & 0xFF);
dbuf->byte_at_put(off++, (ival >> 0) & 0xFF);
}
break;
case 'J':
{
jlong val = o->long_field(field_offset);
dbuf->byte_at_put(off++, (val >> 56) & 0xFF);
dbuf->byte_at_put(off++, (val >> 48) & 0xFF);
dbuf->byte_at_put(off++, (val >> 40) & 0xFF);
dbuf->byte_at_put(off++, (val >> 32) & 0xFF);
dbuf->byte_at_put(off++, (val >> 24) & 0xFF);
dbuf->byte_at_put(off++, (val >> 16) & 0xFF);
dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
}
break;
case 'D':
{
jdouble dval = o->double_field(field_offset);
jlong lval = (*double_to_long_bits_fn)(env, NULL, dval);
dbuf->byte_at_put(off++, (lval >> 56) & 0xFF);
dbuf->byte_at_put(off++, (lval >> 48) & 0xFF);
dbuf->byte_at_put(off++, (lval >> 40) & 0xFF);
dbuf->byte_at_put(off++, (lval >> 32) & 0xFF);
dbuf->byte_at_put(off++, (lval >> 24) & 0xFF);
dbuf->byte_at_put(off++, (lval >> 16) & 0xFF);
dbuf->byte_at_put(off++, (lval >> 8) & 0xFF);
dbuf->byte_at_put(off++, (lval >> 0) & 0xFF);
}
break;
default:
// Illegal typecode
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "illegal typecode");
}
}
JVM_END
// Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, Handle loader, Handle protection_domain, jboolean throwError, TRAPS) {
// Security Note:
// The Java level wrapper will perform the necessary security check allowing
// us to pass the NULL as the initiating class loader.
klassOop klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
KlassHandle klass_handle(THREAD, klass);
// Check if we should initialize the class
if (init && klass_handle->oop_is_instance()) {
klass_handle->initialize(CHECK_NULL);
}
return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror());
}
// Internal SQE debugging support ///////////////////////////////////////////////////////////
#ifndef PRODUCT
extern "C" {
JNIEXPORT jboolean JNICALL JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get);
JNIEXPORT jboolean JNICALL JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get);
JNIEXPORT void JNICALL JVM_VMBreakPoint(JNIEnv *env, jobject obj);
}
JVM_LEAF(jboolean, JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get))
JVMWrapper("JVM_AccessBoolVMFlag");
return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, INTERNAL);
JVM_END
JVM_LEAF(jboolean, JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get))
JVMWrapper("JVM_AccessVMIntFlag");
intx v;
jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, INTERNAL);
*value = (jint)v;
return result;
JVM_END
JVM_ENTRY(void, JVM_VMBreakPoint(JNIEnv *env, jobject obj))
JVMWrapper("JVM_VMBreakPoint");
oop the_obj = JNIHandles::resolve(obj);
BREAKPOINT;
JVM_END
#endif
// Method ///////////////////////////////////////////////////////////////////////////////////////////
JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
JVMWrapper("JVM_InvokeMethod");
Handle method_handle;
if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
method_handle = Handle(THREAD, JNIHandles::resolve(method));
Handle receiver(THREAD, JNIHandles::resolve(obj));
objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
jobject res = JNIHandles::make_local(env, result);
if (JvmtiExport::should_post_vm_object_alloc()) {
oop ret_type = java_lang_reflect_Method::return_type(method_handle());
assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
if (java_lang_Class::is_primitive(ret_type)) {
// Only for primitive type vm allocates memory for java object.
// See box() method.
JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
}
}
return res;
} else {
THROW_0(vmSymbols::java_lang_StackOverflowError());
}
JVM_END
JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
JVMWrapper("JVM_NewInstanceFromConstructor");
oop constructor_mirror = JNIHandles::resolve(c);
objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
jobject res = JNIHandles::make_local(env, result);
if (JvmtiExport::should_post_vm_object_alloc()) {
JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
}
return res;
JVM_END
// Atomic ///////////////////////////////////////////////////////////////////////////////////////////
JVM_LEAF(jboolean, JVM_SupportsCX8())
JVMWrapper("JVM_SupportsCX8");
return VM_Version::supports_cx8();
JVM_END
JVM_ENTRY(jboolean, JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal))
JVMWrapper("JVM_CX8Field");
jlong res;
oop o = JNIHandles::resolve(obj);
intptr_t fldOffs = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid);
volatile jlong* addr = (volatile jlong*)((address)o + fldOffs);
assert(VM_Version::supports_cx8(), "cx8 not supported");
res = Atomic::cmpxchg(newVal, addr, oldVal);
return res == oldVal;
JVM_END
// DTrace ///////////////////////////////////////////////////////////////////
JVM_ENTRY(jint, JVM_DTraceGetVersion(JNIEnv* env))
JVMWrapper("JVM_DTraceGetVersion");
return (jint)JVM_TRACING_DTRACE_VERSION;
JVM_END
JVM_ENTRY(jlong,JVM_DTraceActivate(
JNIEnv* env, jint version, jstring module_name, jint providers_count,
JVM_DTraceProvider* providers))
JVMWrapper("JVM_DTraceActivate");
return DTraceJSDT::activate(
version, module_name, providers_count, providers, CHECK_0);
JVM_END
JVM_ENTRY(jboolean,JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method))
JVMWrapper("JVM_DTraceIsProbeEnabled");
return DTraceJSDT::is_probe_enabled(method);
JVM_END
JVM_ENTRY(void,JVM_DTraceDispose(JNIEnv* env, jlong handle))
JVMWrapper("JVM_DTraceDispose");
DTraceJSDT::dispose(handle);
JVM_END
JVM_ENTRY(jboolean,JVM_DTraceIsSupported(JNIEnv* env))
JVMWrapper("JVM_DTraceIsSupported");
return DTraceJSDT::is_supported();
JVM_END
// Returns an array of all live Thread objects (VM internal JavaThreads,
// jvmti agent threads, and JNI attaching threads are skipped)
// See CR 6404306 regarding JNI attaching threads
JVM_ENTRY(jobjectArray, JVM_GetAllThreads(JNIEnv *env, jclass dummy))
ResourceMark rm(THREAD);
ThreadsListEnumerator tle(THREAD, false, false);
JvmtiVMObjectAllocEventCollector oam;
int num_threads = tle.num_threads();
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NULL);
objArrayHandle threads_ah(THREAD, r);
for (int i = 0; i < num_threads; i++) {
Handle h = tle.get_threadObj(i);
threads_ah->obj_at_put(i, h());
}
return (jobjectArray) JNIHandles::make_local(env, threads_ah());
JVM_END
// Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods
// Return StackTraceElement[][], each element is the stack trace of a thread in
// the corresponding entry in the given threads array
JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads))
JVMWrapper("JVM_DumpThreads");
JvmtiVMObjectAllocEventCollector oam;
// Check if threads is null
if (threads == NULL) {
THROW_(vmSymbols::java_lang_NullPointerException(), 0);
}
objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
objArrayHandle ah(THREAD, a);
int num_threads = ah->length();
// check if threads is non-empty array
if (num_threads == 0) {
THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
}
// check if threads is not an array of objects of Thread class
klassOop k = objArrayKlass::cast(ah->klass())->element_klass();
if (k != SystemDictionary::Thread_klass()) {
THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
}
ResourceMark rm(THREAD);
GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
for (int i = 0; i < num_threads; i++) {
oop thread_obj = ah->obj_at(i);
instanceHandle h(THREAD, (instanceOop) thread_obj);
thread_handle_array->append(h);
}
Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
return (jobjectArray)JNIHandles::make_local(env, stacktraces());
JVM_END
// JVM monitoring and management support
JVM_ENTRY_NO_ENV(void*, JVM_GetManagement(jint version))
return Management::get_jmm_interface(version);
JVM_END
// com.sun.tools.attach.VirtualMachine agent properties support
//
// Initialize the agent properties with the properties maintained in the VM
JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))
JVMWrapper("JVM_InitAgentProperties");
ResourceMark rm;
Handle props(THREAD, JNIHandles::resolve_non_null(properties));
PUTPROP(props, "sun.java.command", Arguments::java_command());
PUTPROP(props, "sun.jvm.flags", Arguments::jvm_flags());
PUTPROP(props, "sun.jvm.args", Arguments::jvm_args());
return properties;
JVM_END
JVM_ENTRY(jobjectArray, JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass))
{
JVMWrapper("JVM_GetEnclosingMethodInfo");
JvmtiVMObjectAllocEventCollector oam;
if (ofClass == NULL) {
return NULL;
}
Handle mirror(THREAD, JNIHandles::resolve_non_null(ofClass));
// Special handling for primitive objects
if (java_lang_Class::is_primitive(mirror())) {
return NULL;
}
klassOop k = java_lang_Class::as_klassOop(mirror());
if (!Klass::cast(k)->oop_is_instance()) {
return NULL;
}
instanceKlassHandle ik_h(THREAD, k);
int encl_method_class_idx = ik_h->enclosing_method_class_index();
if (encl_method_class_idx == 0) {
return NULL;
}
objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::Object_klass(), 3, CHECK_NULL);
objArrayHandle dest(THREAD, dest_o);
klassOop enc_k = ik_h->constants()->klass_at(encl_method_class_idx, CHECK_NULL);
dest->obj_at_put(0, Klass::cast(enc_k)->java_mirror());
int encl_method_method_idx = ik_h->enclosing_method_method_index();
if (encl_method_method_idx != 0) {
Symbol* sym = ik_h->constants()->symbol_at(
extract_low_short_from_int(
ik_h->constants()->name_and_type_at(encl_method_method_idx)));
Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
dest->obj_at_put(1, str());
sym = ik_h->constants()->symbol_at(
extract_high_short_from_int(
ik_h->constants()->name_and_type_at(encl_method_method_idx)));
str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
dest->obj_at_put(2, str());
}
return (jobjectArray) JNIHandles::make_local(dest());
}
JVM_END
JVM_ENTRY(jintArray, JVM_GetThreadStateValues(JNIEnv* env,
jint javaThreadState))
{
// If new thread states are added in future JDK and VM versions,
// this should check if the JDK version is compatible with thread
// states supported by the VM. Return NULL if not compatible.
//
// This function must map the VM java_lang_Thread::ThreadStatus
// to the Java thread state that the JDK supports.
//
typeArrayHandle values_h;
switch (javaThreadState) {
case JAVA_THREAD_STATE_NEW : {
typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
values_h = typeArrayHandle(THREAD, r);
values_h->int_at_put(0, java_lang_Thread::NEW);
break;
}
case JAVA_THREAD_STATE_RUNNABLE : {
typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
values_h = typeArrayHandle(THREAD, r);
values_h->int_at_put(0, java_lang_Thread::RUNNABLE);
break;
}
case JAVA_THREAD_STATE_BLOCKED : {
typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
values_h = typeArrayHandle(THREAD, r);
values_h->int_at_put(0, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER);
break;
}
case JAVA_THREAD_STATE_WAITING : {
typeArrayOop r = oopFactory::new_typeArray(T_INT, 2, CHECK_NULL);
values_h = typeArrayHandle(THREAD, r);
values_h->int_at_put(0, java_lang_Thread::IN_OBJECT_WAIT);
values_h->int_at_put(1, java_lang_Thread::PARKED);
break;
}
case JAVA_THREAD_STATE_TIMED_WAITING : {
typeArrayOop r = oopFactory::new_typeArray(T_INT, 3, CHECK_NULL);
values_h = typeArrayHandle(THREAD, r);
values_h->int_at_put(0, java_lang_Thread::SLEEPING);
values_h->int_at_put(1, java_lang_Thread::IN_OBJECT_WAIT_TIMED);
values_h->int_at_put(2, java_lang_Thread::PARKED_TIMED);
break;
}
case JAVA_THREAD_STATE_TERMINATED : {
typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
values_h = typeArrayHandle(THREAD, r);
values_h->int_at_put(0, java_lang_Thread::TERMINATED);
break;
}
default:
// Unknown state - probably incompatible JDK version
return NULL;
}
return (jintArray) JNIHandles::make_local(env, values_h());
}
JVM_END
JVM_ENTRY(jobjectArray, JVM_GetThreadStateNames(JNIEnv* env,
jint javaThreadState,
jintArray values))
{
// If new thread states are added in future JDK and VM versions,
// this should check if the JDK version is compatible with thread
// states supported by the VM. Return NULL if not compatible.
//
// This function must map the VM java_lang_Thread::ThreadStatus
// to the Java thread state that the JDK supports.
//
ResourceMark rm;
// Check if threads is null
if (values == NULL) {
THROW_(vmSymbols::java_lang_NullPointerException(), 0);
}
typeArrayOop v = typeArrayOop(JNIHandles::resolve_non_null(values));
typeArrayHandle values_h(THREAD, v);
objArrayHandle names_h;
switch (javaThreadState) {
case JAVA_THREAD_STATE_NEW : {
assert(values_h->length() == 1 &&
values_h->int_at(0) == java_lang_Thread::NEW,
"Invalid threadStatus value");
objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1, /* only 1 substate */
CHECK_NULL);
names_h = objArrayHandle(THREAD, r);
Handle name = java_lang_String::create_from_str("NEW", CHECK_NULL);
names_h->obj_at_put(0, name());
break;
}
case JAVA_THREAD_STATE_RUNNABLE : {
assert(values_h->length() == 1 &&
values_h->int_at(0) == java_lang_Thread::RUNNABLE,
"Invalid threadStatus value");
objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1, /* only 1 substate */
CHECK_NULL);
names_h = objArrayHandle(THREAD, r);
Handle name = java_lang_String::create_from_str("RUNNABLE", CHECK_NULL);
names_h->obj_at_put(0, name());
break;
}
case JAVA_THREAD_STATE_BLOCKED : {
assert(values_h->length() == 1 &&
values_h->int_at(0) == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER,
"Invalid threadStatus value");
objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1, /* only 1 substate */
CHECK_NULL);
names_h = objArrayHandle(THREAD, r);
Handle name = java_lang_String::create_from_str("BLOCKED", CHECK_NULL);
names_h->obj_at_put(0, name());
break;
}
case JAVA_THREAD_STATE_WAITING : {
assert(values_h->length() == 2 &&
values_h->int_at(0) == java_lang_Thread::IN_OBJECT_WAIT &&
values_h->int_at(1) == java_lang_Thread::PARKED,
"Invalid threadStatus value");
objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
2, /* number of substates */
CHECK_NULL);
names_h = objArrayHandle(THREAD, r);
Handle name0 = java_lang_String::create_from_str("WAITING.OBJECT_WAIT",
CHECK_NULL);
Handle name1 = java_lang_String::create_from_str("WAITING.PARKED",
CHECK_NULL);
names_h->obj_at_put(0, name0());
names_h->obj_at_put(1, name1());
break;
}
case JAVA_THREAD_STATE_TIMED_WAITING : {
assert(values_h->length() == 3 &&
values_h->int_at(0) == java_lang_Thread::SLEEPING &&
values_h->int_at(1) == java_lang_Thread::IN_OBJECT_WAIT_TIMED &&
values_h->int_at(2) == java_lang_Thread::PARKED_TIMED,
"Invalid threadStatus value");
objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
3, /* number of substates */
CHECK_NULL);
names_h = objArrayHandle(THREAD, r);
Handle name0 = java_lang_String::create_from_str("TIMED_WAITING.SLEEPING",
CHECK_NULL);
Handle name1 = java_lang_String::create_from_str("TIMED_WAITING.OBJECT_WAIT",
CHECK_NULL);
Handle name2 = java_lang_String::create_from_str("TIMED_WAITING.PARKED",
CHECK_NULL);
names_h->obj_at_put(0, name0());
names_h->obj_at_put(1, name1());
names_h->obj_at_put(2, name2());
break;
}
case JAVA_THREAD_STATE_TERMINATED : {
assert(values_h->length() == 1 &&
values_h->int_at(0) == java_lang_Thread::TERMINATED,
"Invalid threadStatus value");
objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
1, /* only 1 substate */
CHECK_NULL);
names_h = objArrayHandle(THREAD, r);
Handle name = java_lang_String::create_from_str("TERMINATED", CHECK_NULL);
names_h->obj_at_put(0, name());
break;
}
default:
// Unknown state - probably incompatible JDK version
return NULL;
}
return (jobjectArray) JNIHandles::make_local(env, names_h());
}
JVM_END
JVM_ENTRY(void, JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size))
{
memset(info, 0, sizeof(info_size));
info->jvm_version = Abstract_VM_Version::jvm_version();
info->update_version = 0; /* 0 in HotSpot Express VM */
info->special_update_version = 0; /* 0 in HotSpot Express VM */
// when we add a new capability in the jvm_version_info struct, we should also
// consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat
// counter defined in runtimeService.cpp.
info->is_attachable = AttachListener::is_attach_supported();
#ifdef KERNEL
info->is_kernel_jvm = 1; // true;
#else // KERNEL
info->is_kernel_jvm = 0; // false;
#endif // KERNEL
}
JVM_END