19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/stringTable.hpp"
27 #include "compiler/compileBroker.hpp"
28 #include "interpreter/interpreter.hpp"
29 #include "interpreter/oopMapCache.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "memory/oopFactory.hpp"
32 #include "prims/jvmtiRedefineClassesTrace.hpp"
33 #include "prims/methodHandles.hpp"
34 #include "runtime/compilationPolicy.hpp"
35 #include "runtime/javaCalls.hpp"
36 #include "runtime/reflection.hpp"
37 #include "runtime/signature.hpp"
38 #include "runtime/stubRoutines.hpp"
39
40
41 /*
42 * JSR 292 reference implementation: method handles
43 * The JDK 7 reference implementation represented method handle
44 * combinations as chains. Each link in the chain had a "vmentry"
45 * field which pointed at a bit of assembly code which performed
46 * one transformation before dispatching to the next link in the chain.
47 *
48 * The current reference implementation pushes almost all code generation
49 * responsibility to (trusted) Java code. A method handle contains a
50 * pointer to its "LambdaForm", which embodies all details of the method
51 * handle's behavior. The LambdaForm is a normal Java object, managed
52 * by a runtime coded in Java.
53 */
54
55 bool MethodHandles::_enabled = false; // set true after successful native linkage
56 MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL;
57
58 //------------------------------------------------------------------------------
59 // MethodHandles::generate_adapters
60 //
61 void MethodHandles::generate_adapters() {
62 if (SystemDictionary::MethodHandle_klass() == NULL) return;
63
64 assert(_adapter_code == NULL, "generate only once");
65
66 ResourceMark rm;
67 TraceTime timer("MethodHandles adapters generation", TraceStartupTime);
68 _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size);
69 if (_adapter_code == NULL)
70 vm_exit_out_of_memory(adapter_code_size, OOM_MALLOC_ERROR,
71 "CodeCache: no room for MethodHandles adapters");
72 {
73 CodeBuffer code(_adapter_code);
74 MethodHandlesAdapterGenerator g(&code);
75 g.generate();
76 code.log_section_sizes("MethodHandlesAdapterBlob");
77 }
78 }
79
80 //------------------------------------------------------------------------------
81 // MethodHandlesAdapterGenerator::generate
82 //
83 void MethodHandlesAdapterGenerator::generate() {
84 // Generate generic method handle adapters.
85 // Generate interpreter entries
86 for (Interpreter::MethodKind mk = Interpreter::method_handle_invoke_FIRST;
87 mk <= Interpreter::method_handle_invoke_LAST;
88 mk = Interpreter::MethodKind(1 + (int)mk)) {
89 vmIntrinsics::ID iid = Interpreter::method_handle_intrinsic(mk);
90 StubCodeMark mark(this, "MethodHandle::interpreter_entry", vmIntrinsics::name_at(iid));
91 address entry = MethodHandles::generate_method_handle_interpreter_entry(_masm, iid);
92 if (entry != NULL) {
93 Interpreter::set_entry_for_kind(mk, entry);
94 }
95 // If the entry is not set, it will throw AbstractMethodError.
96 }
97 }
1384 oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror();
1385 MH_class = (jclass) JNIHandles::make_local(env, mirror);
1386 }
1387
1388 if (enable_MH) {
1389 ThreadToNativeFromVM ttnfv(thread);
1390
1391 if (enable_MH) {
1392 enable_MH = register_natives(env, MHN_class, MHN_methods, sizeof(MHN_methods)/sizeof(JNINativeMethod));
1393 }
1394 if (enable_MH) {
1395 enable_MH = register_natives(env, MH_class, MH_methods, sizeof(MH_methods)/sizeof(JNINativeMethod));
1396 }
1397 }
1398
1399 if (TraceInvokeDynamic) {
1400 tty->print_cr("MethodHandle support loaded (using LambdaForms)");
1401 }
1402
1403 if (enable_MH) {
1404 MethodHandles::generate_adapters();
1405 MethodHandles::set_enabled(true);
1406 }
1407 }
1408 JVM_END
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/stringTable.hpp"
27 #include "compiler/compileBroker.hpp"
28 #include "interpreter/interpreter.hpp"
29 #include "interpreter/oopMapCache.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "memory/oopFactory.hpp"
32 #include "prims/jvmtiRedefineClassesTrace.hpp"
33 #include "prims/methodHandles.hpp"
34 #include "runtime/compilationPolicy.hpp"
35 #include "runtime/javaCalls.hpp"
36 #include "runtime/reflection.hpp"
37 #include "runtime/signature.hpp"
38 #include "runtime/stubRoutines.hpp"
39 #include "utilities/exceptions.hpp"
40
41
42 /*
43 * JSR 292 reference implementation: method handles
44 * The JDK 7 reference implementation represented method handle
45 * combinations as chains. Each link in the chain had a "vmentry"
46 * field which pointed at a bit of assembly code which performed
47 * one transformation before dispatching to the next link in the chain.
48 *
49 * The current reference implementation pushes almost all code generation
50 * responsibility to (trusted) Java code. A method handle contains a
51 * pointer to its "LambdaForm", which embodies all details of the method
52 * handle's behavior. The LambdaForm is a normal Java object, managed
53 * by a runtime coded in Java.
54 */
55
56 bool MethodHandles::_enabled = false; // set true after successful native linkage
57 MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL;
58
59
60 /**
61 * Generates method handle adapters. Returns 'false' if memory allocation
62 * failed and true otherwise.
63 */
64 bool MethodHandles::generate_adapters() {
65 if (SystemDictionary::MethodHandle_klass() == NULL) {
66 return true;
67 }
68
69 assert(_adapter_code == NULL, "generate only once");
70
71 ResourceMark rm;
72 TraceTime timer("MethodHandles adapters generation", TraceStartupTime);
73 _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size);
74 if (_adapter_code == NULL) {
75 return false;
76 }
77
78 CodeBuffer code(_adapter_code);
79 MethodHandlesAdapterGenerator g(&code);
80 g.generate();
81 code.log_section_sizes("MethodHandlesAdapterBlob");
82 return true;
83 }
84
85 //------------------------------------------------------------------------------
86 // MethodHandlesAdapterGenerator::generate
87 //
88 void MethodHandlesAdapterGenerator::generate() {
89 // Generate generic method handle adapters.
90 // Generate interpreter entries
91 for (Interpreter::MethodKind mk = Interpreter::method_handle_invoke_FIRST;
92 mk <= Interpreter::method_handle_invoke_LAST;
93 mk = Interpreter::MethodKind(1 + (int)mk)) {
94 vmIntrinsics::ID iid = Interpreter::method_handle_intrinsic(mk);
95 StubCodeMark mark(this, "MethodHandle::interpreter_entry", vmIntrinsics::name_at(iid));
96 address entry = MethodHandles::generate_method_handle_interpreter_entry(_masm, iid);
97 if (entry != NULL) {
98 Interpreter::set_entry_for_kind(mk, entry);
99 }
100 // If the entry is not set, it will throw AbstractMethodError.
101 }
102 }
1389 oop mirror = SystemDictionary::MethodHandle_klass()->java_mirror();
1390 MH_class = (jclass) JNIHandles::make_local(env, mirror);
1391 }
1392
1393 if (enable_MH) {
1394 ThreadToNativeFromVM ttnfv(thread);
1395
1396 if (enable_MH) {
1397 enable_MH = register_natives(env, MHN_class, MHN_methods, sizeof(MHN_methods)/sizeof(JNINativeMethod));
1398 }
1399 if (enable_MH) {
1400 enable_MH = register_natives(env, MH_class, MH_methods, sizeof(MH_methods)/sizeof(JNINativeMethod));
1401 }
1402 }
1403
1404 if (TraceInvokeDynamic) {
1405 tty->print_cr("MethodHandle support loaded (using LambdaForms)");
1406 }
1407
1408 if (enable_MH) {
1409 if (MethodHandles::generate_adapters() == false) {
1410 THROW_MSG(vmSymbols::java_lang_VirtualMachineError(), "Out of space in CodeCache for method handle adapters");
1411 }
1412 MethodHandles::set_enabled(true);
1413 }
1414 }
1415 JVM_END
|