Mercurial > hg > truffle
diff src/share/vm/prims/methodHandles.cpp @ 4137:04b9a2566eec
Merge with hsx23/hotspot.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 21:40:27 +0100 |
parents | 44ce519bc3d1 |
children | 15d394228cfa |
line wrap: on
line diff
--- a/src/share/vm/prims/methodHandles.cpp Sat Dec 17 20:50:09 2011 +0100 +++ b/src/share/vm/prims/methodHandles.cpp Sat Dec 17 21:40:27 2011 +0100 @@ -158,6 +158,8 @@ "adapter_fold/4/ref", "adapter_fold/5/ref", + "adapter_opt_profiling", + NULL }; @@ -204,9 +206,12 @@ _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size); if (_adapter_code == NULL) vm_exit_out_of_memory(adapter_code_size, "CodeCache: no room for MethodHandles adapters"); - CodeBuffer code(_adapter_code); - MethodHandlesAdapterGenerator g(&code); - g.generate(); + { + CodeBuffer code(_adapter_code); + MethodHandlesAdapterGenerator g(&code); + g.generate(); + code.log_section_sizes("MethodHandlesAdapterBlob"); + } } //------------------------------------------------------------------------------ @@ -518,7 +523,7 @@ int slot = java_lang_reflect_Field::slot(target_oop); // fd.index() int mods = java_lang_reflect_Field::modifiers(target_oop); klassOop k = java_lang_Class::as_klassOop(clazz); - int offset = instanceKlass::cast(k)->offset_from_fields(slot); + int offset = instanceKlass::cast(k)->field_offset(slot); init_MemberName(mname_oop, k, accessFlags_from(mods), offset); } else { KlassHandle receiver_limit; int decode_flags = 0; @@ -1016,7 +1021,7 @@ && CompilationPolicy::can_be_compiled(m)) { // Force compilation CompileBroker::compile_method(m, InvocationEntryBci, - CompLevel_initial_compile, + CompilationPolicy::policy()->initial_compile_level(), methodHandle(), 0, "MethodHandleNatives.getTarget", CHECK_NULL); } @@ -1630,8 +1635,6 @@ THROW(vmSymbols::java_lang_InternalError()); } - java_lang_invoke_MethodHandle::init_vmslots(mh()); - if (VerifyMethodHandles) { // The privileged code which invokes this routine should not make // a mistake about types, but it's better to verify. @@ -1754,7 +1757,6 @@ if (m.is_null()) { THROW(vmSymbols::java_lang_InternalError()); } if (m->is_abstract()) { THROW(vmSymbols::java_lang_AbstractMethodError()); } - java_lang_invoke_MethodHandle::init_vmslots(mh()); int vmargslot = m->size_of_parameters() - 1; assert(java_lang_invoke_BoundMethodHandle::vmargslot(mh()) == vmargslot, ""); @@ -1860,7 +1862,6 @@ THROW(vmSymbols::java_lang_InternalError()); } - java_lang_invoke_MethodHandle::init_vmslots(mh()); int argslot = java_lang_invoke_BoundMethodHandle::vmargslot(mh()); if (VerifyMethodHandles) { @@ -2653,6 +2654,11 @@ // Finalize the conversion field. (Note that it is final to Java code.) java_lang_invoke_AdapterMethodHandle::set_conversion(mh(), new_conversion); + if (java_lang_invoke_CountingMethodHandle::is_instance(mh())) { + assert(ek_orig == _adapter_retype_only, "only one handled"); + ek_opt = _adapter_opt_profiling; + } + // Done! java_lang_invoke_MethodHandle::set_vmentry(mh(), entry(ek_opt)); @@ -2679,6 +2685,7 @@ java_lang_invoke_MethodTypeForm::init_vmlayout(mtform(), cookie); } } + assert(java_lang_invoke_MethodTypeForm::vmslots(mtform()) == argument_slot_count(mtype()), "must agree"); } #ifdef ASSERT @@ -2713,7 +2720,7 @@ && CompilationPolicy::can_be_compiled(m)) { // Force compilation CompileBroker::compile_method(m, InvocationEntryBci, - CompLevel_initial_compile, + CompilationPolicy::policy()->initial_compile_level(), methodHandle(), 0, "StressMethodHandleWalk", CHECK); } @@ -2905,8 +2912,12 @@ return MethodHandles::stack_move_unit(); case MethodHandles::GC_CONV_OP_IMPLEMENTED_MASK: return MethodHandles::adapter_conversion_ops_supported_mask(); - case MethodHandles::GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS: - return MethodHandles::OP_ROT_ARGS_DOWN_LIMIT_BIAS; + case MethodHandles::GC_COUNT_GWT: +#ifdef COMPILER2 + return true; +#else + return false; +#endif } return 0; } @@ -3070,6 +3081,30 @@ } JVM_END +JVM_ENTRY(void, MHN_setCallSiteTargetNormal(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) { + Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh)); + Handle target (THREAD, JNIHandles::resolve(target_jh)); + { + // Walk all nmethods depending on this call site. + MutexLocker mu(Compile_lock, thread); + Universe::flush_dependents_on(call_site, target); + } + java_lang_invoke_CallSite::set_target(call_site(), target()); +} +JVM_END + +JVM_ENTRY(void, MHN_setCallSiteTargetVolatile(JNIEnv* env, jobject igcls, jobject call_site_jh, jobject target_jh)) { + Handle call_site(THREAD, JNIHandles::resolve_non_null(call_site_jh)); + Handle target (THREAD, JNIHandles::resolve(target_jh)); + { + // Walk all nmethods depending on this call site. + MutexLocker mu(Compile_lock, thread); + Universe::flush_dependents_on(call_site, target); + } + java_lang_invoke_CallSite::set_target_volatile(call_site(), target()); +} +JVM_END + methodOop MethodHandles::resolve_raise_exception_method(TRAPS) { if (_raise_exception_method != NULL) { // no need to do it twice @@ -3126,12 +3161,15 @@ /// JVM_RegisterMethodHandleMethods +#undef CS // Solaris builds complain + #define LANG "Ljava/lang/" #define JLINV "Ljava/lang/invoke/" #define OBJ LANG"Object;" #define CLS LANG"Class;" #define STRG LANG"String;" +#define CS JLINV"CallSite;" #define MT JLINV"MethodType;" #define MH JLINV"MethodHandle;" #define MEM JLINV"MemberName;" @@ -3142,29 +3180,34 @@ #define CC (char*) /*cast a literal from (const char*)*/ #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) -// These are the native methods on sun.invoke.MethodHandleNatives. +// These are the native methods on java.lang.invoke.MethodHandleNatives. static JNINativeMethod methods[] = { // void init(MemberName self, AccessibleObject ref) - {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHN_init_AMH)}, - {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHN_init_BMH)}, - {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHN_init_DMH)}, - {CC"init", CC"("MT")V", FN_PTR(MHN_init_MT)}, - {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, - {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, - {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHN_resolve_Mem)}, - {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHN_getTarget)}, - {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, + {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHN_init_AMH)}, + {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHN_init_BMH)}, + {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHN_init_DMH)}, + {CC"init", CC"("MT")V", FN_PTR(MHN_init_MT)}, + {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, + {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, + {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHN_resolve_Mem)}, + {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHN_getTarget)}, + {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, // static native int getNamedCon(int which, Object[] name) - {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)}, + {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)}, // static native int getMembers(Class<?> defc, String matchName, String matchSig, // int matchFlags, Class<?> caller, int skip, MemberName[] results); - {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} + {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} +}; + +static JNINativeMethod call_site_methods[] = { + {CC"setCallSiteTargetNormal", CC"("CS""MH")V", FN_PTR(MHN_setCallSiteTargetNormal)}, + {CC"setCallSiteTargetVolatile", CC"("CS""MH")V", FN_PTR(MHN_setCallSiteTargetVolatile)} }; static JNINativeMethod invoke_methods[] = { // void init(MemberName self, AccessibleObject ref) - {CC"invoke", CC"(["OBJ")"OBJ, FN_PTR(MH_invoke_UOE)}, - {CC"invokeExact", CC"(["OBJ")"OBJ, FN_PTR(MH_invokeExact_UOE)} + {CC"invoke", CC"(["OBJ")"OBJ, FN_PTR(MH_invoke_UOE)}, + {CC"invokeExact", CC"(["OBJ")"OBJ, FN_PTR(MH_invokeExact_UOE)} }; // This one function is exported, used by NativeLookup. @@ -3177,11 +3220,11 @@ return; // bind nothing } + assert(!MethodHandles::enabled(), "must not be enabled"); bool enable_MH = true; { ThreadToNativeFromVM ttnfv(thread); - int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod)); if (!env->ExceptionOccurred()) { const char* L_MH_name = (JLINV "MethodHandle"); @@ -3190,11 +3233,16 @@ status = env->RegisterNatives(MH_class, invoke_methods, sizeof(invoke_methods)/sizeof(JNINativeMethod)); } if (env->ExceptionOccurred()) { - MethodHandles::set_enabled(false); warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); enable_MH = false; env->ExceptionClear(); } + + status = env->RegisterNatives(MHN_class, call_site_methods, sizeof(call_site_methods)/sizeof(JNINativeMethod)); + if (env->ExceptionOccurred()) { + // Exception is okay until 7087357 + env->ExceptionClear(); + } } if (enable_MH) {