jvm.cpp revision 3937
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A#include "precompiled.hpp"
0N/A#include "classfile/classLoader.hpp"
0N/A#include "classfile/javaAssertions.hpp"
0N/A#include "classfile/javaClasses.hpp"
0N/A#include "classfile/symbolTable.hpp"
0N/A#include "classfile/systemDictionary.hpp"
0N/A#include "classfile/vmSymbols.hpp"
0N/A#include "gc_interface/collectedHeap.inline.hpp"
0N/A#include "memory/oopFactory.hpp"
0N/A#include "memory/universe.inline.hpp"
0N/A#include "oops/fieldStreams.hpp"
0N/A#include "oops/instanceKlass.hpp"
0N/A#include "oops/objArrayKlass.hpp"
0N/A#include "oops/methodOop.hpp"
0N/A#include "prims/jvm_misc.hpp"
0N/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/interfaceSupport.hpp"
0N/A#include "runtime/javaCalls.hpp"
0N/A#include "runtime/jfieldIDWorkaround.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"
4063N/A#include "services/attachListener.hpp"
0N/A#include "services/management.hpp"
4063N/A#include "services/threadService.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#ifdef TARGET_OS_FAMILY_linux
0N/A# include "jvm_linux.h"
0N/A#ifdef TARGET_OS_FAMILY_solaris
0N/A# include "jvm_solaris.h"
0N/A#ifdef TARGET_OS_FAMILY_windows
0N/A# include "jvm_windows.h"
0N/A#ifdef TARGET_OS_FAMILY_bsd
2370N/A such ctors and calls MUST NOT come between an oop declaration/init and its
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 if (!vfst.method()->method_holder()->klass_part()->is_subclass_of(SystemDictionary::ClassLoader_klass())&&
0N/A last_caller = m;
found_it = true;
found_it = true;
if (s != NULL) {
if (HAS_PENDING_EXCEPTION) {
#ifdef ASSERT
if (TraceJVMCalls) {
if ( (WarnOnStalledSpinLock > 0)
if (e != NULL) e->increment_count(); // Due to bug in VC++, we need a NULL check here eventhough it should never happen!
#define JVMWrapper4(arg1, arg2, arg3, arg4) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3, arg4)
return JVM_INTERFACE_VERSION;
Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK);
THREAD);
// Add the sun.management.compiler property for the compiler's name
#define CSIZE
#ifdef TIERED
#if defined(COMPILER1)
return properties;
if (!DisableExplicitGC) {
return convert_size_t_to_jlong(n);
size_t n;
return convert_size_t_to_jlong(n);
return convert_size_t_to_jlong(n);
JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
#ifdef ASSERT
return JNI_FALSE;
return JNI_FALSE;
return JNI_FALSE;
return NULL;
const char* name))
return NULL;
if (k == NULL) {
return NULL;
if (TraceClassResolution) {
if (throwError) {
return result;
return result;
if (UsePerfData) {
if (UsePerfData) {
THREAD);
verify != 0,
JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
return NULL;
if (UsePerfData) {
THREAD);
Handle(),
// Reflection support //////////////////////////////////////////////////////////////////////////////
const char* name;
int size;
return NULL;
return JNI_FALSE;
return result;
return NULL;
// Signers are only set once, ClassLoader.java, and thus shouldn't
return NULL;
// Obsolete since 1.2 (Class.setProtectionDomain removed), although
JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))
if (m.is_null() || !m->is_method() || !methodOop(m())->is_public() || methodOop(m())->is_static()) {
// invoke the Object run() in the action object. We cannot use call_interface here, since the static type
// is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction
assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element");
if (HAS_PENDING_EXCEPTION) {
// Throw a java.security.PrivilegedActionException(Exception e) exception
&args);
class RegisterArrayForGC {
~RegisterArrayForGC() {
bool is_privileged = false;
is_privileged = true;
if (is_privileged) break;
oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
return k->modifier_flags();
// Inner class reflection ///////////////////////////////////////////////////////////////////////////////
! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) {
int members = 0;
if (outer_klass == k()) {
members++;
for(int i = 0; i < members; i++) {
! Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_instance()) {
return NULL;
bool inner_is_member = false;
// should be in instanceKlass.cpp, but is here for historical reasons
bool* inner_is_member,
TRAPS) {
return NULL;
bool found = false;
*inner_is_member = false;
if (ioff != 0) {
*inner_is_member = true;
if (encl_method_class_idx != 0) {
*inner_is_member = false;
return outer_klass();
return NULL;
return NULL;
true, &fd)) {
&fd)) {
int slot = 0;
if (m == NULL) {
JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
bool skip_backtrace = false;
int num_fields;
if (publicOnly) {
num_fields = 0;
num_fields--;
skip_backtrace = true;
objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
int out_idx = 0;
if (skip_backtrace) {
++out_idx;
JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
|| Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
int num_methods = 0;
for (i = 0; i < methods_length; i++) {
++num_methods;
objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Method_klass(), num_methods, CHECK_NULL);
int out_idx = 0;
for (i = 0; i < methods_length; i++) {
++out_idx;
JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
|| Klass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(ofClass)))->oop_is_javaArray()) {
int num_constructors = 0;
for (i = 0; i < methods_length; i++) {
objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Constructor_klass(), num_constructors, CHECK_NULL);
int out_idx = 0;
for (i = 0; i < methods_length; i++) {
++out_idx;
return NULL;
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
static jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
if (force_resolution) {
if (m.is_null()) {
JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
return res;
JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
return res;
static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
if (force_resolution) {
JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
return res;
JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
return res;
JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index))
constantPoolHandle cp = constantPoolHandle(THREAD, constantPoolOop(JNIHandles::resolve_non_null(jcpool)));
// Please, refer to the description in the jvmtiThreadSate.hpp.
JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
if (length > 0) {
for (int i = 0; i < length; i++) {
JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
case JVM_CONSTANT_Fieldref:
return NULL;
case JVM_CONSTANT_Methodref:
return NULL;
case JVM_CONSTANT_Methodref:
return NULL;
case JVM_CONSTANT_Fieldref:
return NULL;
case JVM_CONSTANT_Fieldref: {
return NULL;
case JVM_CONSTANT_Methodref:
case JVM_CONSTANT_InterfaceMethodref: {
return NULL;
case JVM_CONSTANT_Fieldref: {
JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
case JVM_CONSTANT_Methodref:
case JVM_CONSTANT_InterfaceMethodref: {
for (int i = 0; i < methods_count; i++) {
// Misc //////////////////////////////////////////////////////////////////////////////////////////////
// IO functions ////////////////////////////////////////////////////////////////////////////////////////
if (result >= 0) {
return result;
switch(errno) {
case EEXIST:
return JVM_EEXIST;
int len;
return len;
int len;
return len;
int len;
return len;
void jio_print(const char* s) {
obj,
THREAD);
bool throw_illegal_thread_state = false;
throw_illegal_thread_state = true;
if (throw_illegal_thread_state) {
delete native_thread;
"JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]",
#ifndef USDT2
if (ConvertYieldToSleep) {
if (millis < 0) {
#ifndef USDT2
millis);
if (millis == 0) {
if (ConvertSleepToYield) {
if (!HAS_PENDING_EXCEPTION) {
#ifndef USDT2
#ifndef USDT2
bool throw_illegal_thread_state = false;
int count = 0;
throw_illegal_thread_state = true;
if (throw_illegal_thread_state) {
return count;
JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted))
return JNI_FALSE;
// java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
if (trusted) return true;
if (!m->is_native()) {
return NULL;
if (!m->is_native()) {
return NULL;
int depth = 0;
depth++;
last = l;
int index = 0;
int depth = 0;
return depth;
depth++;
int depth = 0;
if (!m->is_native()) {
return depth;
depth++;
bool force_verify_field_access(klassOop current_class, klassOop field_class, AccessFlags access, bool classloader_only) {
return (!access.is_private() && instanceKlass::cast(current_class)->is_same_class_package(field_class));
JVM_ENTRY(jobject, JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass))
if (m.is_null()) {
return NULL;
false, thread);
return result;
// Array ///////////////////////////////////////////////////////////////////////////////////////////
return arrayOop(a);
return a->length();
return value;
if (a->is_objArray()) {
JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode))
oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL);
return result;
JVM_LEAF(jint, JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen))
return result;
return result;
return result;
void *load_result;
return load_result;
return g_isnan(a);
void initialize_converter_functions() {
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"));
if (nfids == 0) return;
int field_offset;
off++;
off++;
if (nfids == 0) return;
jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, Handle loader, Handle protection_domain, jboolean throwError, TRAPS) {
klassOop klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
#ifndef PRODUCT
JNIEXPORT jboolean JNICALL JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get);
return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, INTERNAL);
intx v;
jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, INTERNAL);
return result;
// Method ///////////////////////////////////////////////////////////////////////////////////////////
return res;
return res;
// Atomic ///////////////////////////////////////////////////////////////////////////////////////////
JVM_ENTRY(jboolean, JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal))
objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NULL);
for (int i = 0; i < num_threads; i++) {
if (num_threads == 0) {
GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
for (int i = 0; i < num_threads; i++) {
Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
// com.sun.tools.attach.VirtualMachine agent properties support
return properties;
return NULL;
return NULL;
return NULL;
if (encl_method_class_idx == 0) {
return NULL;
if (encl_method_method_idx != 0) {
switch (javaThreadState) {
case JAVA_THREAD_STATE_NEW : {
case JAVA_THREAD_STATE_RUNNABLE : {
case JAVA_THREAD_STATE_BLOCKED : {
case JAVA_THREAD_STATE_WAITING : {
case JAVA_THREAD_STATE_TIMED_WAITING : {
case JAVA_THREAD_STATE_TERMINATED : {
return NULL;
switch (javaThreadState) {
case JAVA_THREAD_STATE_NEW : {
case JAVA_THREAD_STATE_RUNNABLE : {
case JAVA_THREAD_STATE_BLOCKED : {
case JAVA_THREAD_STATE_WAITING : {
case JAVA_THREAD_STATE_TIMED_WAITING : {
case JAVA_THREAD_STATE_TERMINATED : {
return NULL;
// counter defined in runtimeService.cpp.
#ifdef KERNEL