25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/dependencyContext.hpp"
31 #include "compiler/compileBroker.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "interpreter/oopMapCache.hpp"
34 #include "interpreter/linkResolver.hpp"
35 #include "memory/allocation.inline.hpp"
36 #include "memory/oopFactory.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "memory/universe.hpp"
39 #include "oops/objArrayKlass.hpp"
40 #include "oops/objArrayOop.inline.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "oops/typeArrayOop.inline.hpp"
43 #include "prims/methodHandles.hpp"
44 #include "runtime/compilationPolicy.hpp"
45 #include "runtime/fieldDescriptor.inline.hpp"
46 #include "runtime/handles.inline.hpp"
47 #include "runtime/interfaceSupport.inline.hpp"
48 #include "runtime/javaCalls.hpp"
49 #include "runtime/jniHandles.inline.hpp"
50 #include "runtime/timerTrace.hpp"
51 #include "runtime/reflection.hpp"
52 #include "runtime/safepointVerifiers.hpp"
53 #include "runtime/signature.hpp"
54 #include "runtime/stubRoutines.hpp"
55 #include "utilities/exceptions.hpp"
56
57
58 /*
59 * JSR 292 reference implementation: method handles
60 * The JDK 7 reference implementation represented method handle
61 * combinations as chains. Each link in the chain had a "vmentry"
62 * field which pointed at a bit of assembly code which performed
63 * one transformation before dispatching to the next link in the chain.
64 *
1092 oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
1093 DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1094 deps.clean_unloading_dependents();
1095 }
1096
1097 void MethodHandles::flush_dependent_nmethods(Handle call_site, Handle target) {
1098 assert_lock_strong(Compile_lock);
1099
1100 int marked = 0;
1101 CallSiteDepChange changes(call_site, target);
1102 {
1103 NoSafepointVerifier nsv;
1104 MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1105
1106 oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site());
1107 DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1108 marked = deps.mark_dependent_nmethods(changes);
1109 }
1110 if (marked > 0) {
1111 // At least one nmethod has been marked for deoptimization.
1112 VM_Deoptimize op;
1113 VMThread::execute(&op);
1114 }
1115 }
1116
1117 void MethodHandles::trace_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid) {
1118 if (TraceMethodHandles) {
1119 const char* name = vmIntrinsics::name_at(iid);
1120 if (*name == '_') name += 1;
1121 const size_t len = strlen(name) + 50;
1122 char* qname = NEW_C_HEAP_ARRAY(char, len, mtInternal);
1123 const char* suffix = "";
1124 if (is_signature_polymorphic(iid)) {
1125 if (is_signature_polymorphic_static(iid))
1126 suffix = "/static";
1127 else
1128 suffix = "/private";
1129 }
1130 jio_snprintf(qname, len, "MethodHandle::interpreter_entry::%s%s", name, suffix);
1131 trace_method_handle(_masm, qname);
1132 // Note: Don't free the allocated char array because it's used
1133 // during runtime.
1489 }
1490 JVM_END
1491
1492 // It is called by a Cleaner object which ensures that dropped CallSites properly
1493 // deallocate their dependency information.
1494 JVM_ENTRY(void, MHN_clearCallSiteContext(JNIEnv* env, jobject igcls, jobject context_jh)) {
1495 Handle context(THREAD, JNIHandles::resolve_non_null(context_jh));
1496 {
1497 // Walk all nmethods depending on this call site.
1498 MutexLocker mu1(Compile_lock, thread);
1499
1500 int marked = 0;
1501 {
1502 NoSafepointVerifier nsv;
1503 MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1504 DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context());
1505 marked = deps.remove_all_dependents();
1506 }
1507 if (marked > 0) {
1508 // At least one nmethod has been marked for deoptimization
1509 VM_Deoptimize op;
1510 VMThread::execute(&op);
1511 }
1512 }
1513 }
1514 JVM_END
1515
1516 /**
1517 * Throws a java/lang/UnsupportedOperationException unconditionally.
1518 * This is required by the specification of MethodHandle.invoke if
1519 * invoked directly.
1520 */
1521 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
1522 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively");
1523 return NULL;
1524 }
1525 JVM_END
1526
1527 /**
1528 * Throws a java/lang/UnsupportedOperationException unconditionally.
1529 * This is required by the specification of MethodHandle.invokeExact if
1530 * invoked directly.
|
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.inline.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/dependencyContext.hpp"
31 #include "compiler/compileBroker.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "interpreter/oopMapCache.hpp"
34 #include "interpreter/linkResolver.hpp"
35 #include "memory/allocation.inline.hpp"
36 #include "memory/oopFactory.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "memory/universe.hpp"
39 #include "oops/objArrayKlass.hpp"
40 #include "oops/objArrayOop.inline.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "oops/typeArrayOop.inline.hpp"
43 #include "prims/methodHandles.hpp"
44 #include "runtime/compilationPolicy.hpp"
45 #include "runtime/deoptimization.hpp"
46 #include "runtime/fieldDescriptor.inline.hpp"
47 #include "runtime/handles.inline.hpp"
48 #include "runtime/interfaceSupport.inline.hpp"
49 #include "runtime/javaCalls.hpp"
50 #include "runtime/jniHandles.inline.hpp"
51 #include "runtime/timerTrace.hpp"
52 #include "runtime/reflection.hpp"
53 #include "runtime/safepointVerifiers.hpp"
54 #include "runtime/signature.hpp"
55 #include "runtime/stubRoutines.hpp"
56 #include "utilities/exceptions.hpp"
57
58
59 /*
60 * JSR 292 reference implementation: method handles
61 * The JDK 7 reference implementation represented method handle
62 * combinations as chains. Each link in the chain had a "vmentry"
63 * field which pointed at a bit of assembly code which performed
64 * one transformation before dispatching to the next link in the chain.
65 *
1093 oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site);
1094 DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1095 deps.clean_unloading_dependents();
1096 }
1097
1098 void MethodHandles::flush_dependent_nmethods(Handle call_site, Handle target) {
1099 assert_lock_strong(Compile_lock);
1100
1101 int marked = 0;
1102 CallSiteDepChange changes(call_site, target);
1103 {
1104 NoSafepointVerifier nsv;
1105 MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1106
1107 oop context = java_lang_invoke_CallSite::context_no_keepalive(call_site());
1108 DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context);
1109 marked = deps.mark_dependent_nmethods(changes);
1110 }
1111 if (marked > 0) {
1112 // At least one nmethod has been marked for deoptimization.
1113 Deoptimization::deoptimize_all_marked();
1114 }
1115 }
1116
1117 void MethodHandles::trace_method_handle_interpreter_entry(MacroAssembler* _masm, vmIntrinsics::ID iid) {
1118 if (TraceMethodHandles) {
1119 const char* name = vmIntrinsics::name_at(iid);
1120 if (*name == '_') name += 1;
1121 const size_t len = strlen(name) + 50;
1122 char* qname = NEW_C_HEAP_ARRAY(char, len, mtInternal);
1123 const char* suffix = "";
1124 if (is_signature_polymorphic(iid)) {
1125 if (is_signature_polymorphic_static(iid))
1126 suffix = "/static";
1127 else
1128 suffix = "/private";
1129 }
1130 jio_snprintf(qname, len, "MethodHandle::interpreter_entry::%s%s", name, suffix);
1131 trace_method_handle(_masm, qname);
1132 // Note: Don't free the allocated char array because it's used
1133 // during runtime.
1489 }
1490 JVM_END
1491
1492 // It is called by a Cleaner object which ensures that dropped CallSites properly
1493 // deallocate their dependency information.
1494 JVM_ENTRY(void, MHN_clearCallSiteContext(JNIEnv* env, jobject igcls, jobject context_jh)) {
1495 Handle context(THREAD, JNIHandles::resolve_non_null(context_jh));
1496 {
1497 // Walk all nmethods depending on this call site.
1498 MutexLocker mu1(Compile_lock, thread);
1499
1500 int marked = 0;
1501 {
1502 NoSafepointVerifier nsv;
1503 MutexLocker mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1504 DependencyContext deps = java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(context());
1505 marked = deps.remove_all_dependents();
1506 }
1507 if (marked > 0) {
1508 // At least one nmethod has been marked for deoptimization
1509 Deoptimization::deoptimize_all_marked();
1510 }
1511 }
1512 }
1513 JVM_END
1514
1515 /**
1516 * Throws a java/lang/UnsupportedOperationException unconditionally.
1517 * This is required by the specification of MethodHandle.invoke if
1518 * invoked directly.
1519 */
1520 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv* env, jobject mh, jobjectArray args)) {
1521 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "MethodHandle.invoke cannot be invoked reflectively");
1522 return NULL;
1523 }
1524 JVM_END
1525
1526 /**
1527 * Throws a java/lang/UnsupportedOperationException unconditionally.
1528 * This is required by the specification of MethodHandle.invokeExact if
1529 * invoked directly.
|