6655646: dynamic languages need dynamically linked call sites

Invokedynamic instruction (JSR 292 RI)

Reviewed-by: twisti, never
This commit is contained in:
John R Rose 2009-04-21 23:21:04 -07:00
parent fd05c28901
commit 34c1d72421
65 changed files with 1457 additions and 264 deletions

View file

@ -2279,6 +2279,16 @@ JVM_ENTRY(jint, MHI_getMembers(JNIEnv *env, jobject igcls,
JVM_END
JVM_ENTRY(void, MH_linkCallSite(JNIEnv *env, jobject igcls, jobject site_jh, jobject target_jh)) {
// No special action required, yet.
oop site_oop = JNIHandles::resolve(site_jh);
if (site_oop == NULL || site_oop->klass() != SystemDictionary::CallSiteImpl_klass())
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "call site");
sun_dyn_CallSiteImpl::set_target(site_oop, JNIHandles::resolve(target_jh));
}
JVM_END
/// JVM_RegisterMethodHandleMethods
#define ADR "J"
@ -2297,6 +2307,7 @@ JVM_END
#define AMH IDYN"AdapterMethodHandle;"
#define BMH IDYN"BoundMethodHandle;"
#define DMH IDYN"DirectMethodHandle;"
#define CSTI IDYN"CallSiteImpl;"
#define CC (char*) /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
@ -2320,12 +2331,19 @@ static JNINativeMethod methods[] = {
{CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHI_getMembers)}
};
// More entry points specifically for EnableInvokeDynamic.
static JNINativeMethod methods2[] = {
{CC"linkCallSite", CC"("CSTI MH")V", FN_PTR(MH_linkCallSite)}
};
// This one function is exported, used by NativeLookup.
JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) {
assert(MethodHandles::spot_check_entry_names(), "entry enum is OK");
// note: this explicit warning-producing stuff will be replaced by auto-detection of the JSR 292 classes
if (!EnableMethodHandles) {
warning("JSR 292 method handles are disabled in this JVM. Use -XX:+EnableMethodHandles to enable.");
return; // bind nothing
@ -2343,5 +2361,23 @@ JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class))
MethodHandles::set_enabled(true);
}
}
if (!EnableInvokeDynamic) {
warning("JSR 292 invokedynamic is disabled in this JVM. Use -XX:+EnableInvokeDynamic to enable.");
return; // bind nothing
}
{
ThreadToNativeFromVM ttnfv(thread);
int status = env->RegisterNatives(MHN_class, methods2, sizeof(methods2)/sizeof(JNINativeMethod));
if (env->ExceptionOccurred()) {
MethodHandles::set_enabled(false);
warning("JSR 292 method handle code is mismatched to this JVM. Disabling support.");
env->ExceptionClear();
} else {
MethodHandles::set_enabled(true);
}
}
}
JVM_END