1 /* 2 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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/javaClasses.inline.hpp" 27 #include "classfile/stringTable.hpp" 28 #include "code/codeCache.hpp" 29 #include "code/codeCacheExtensions.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 "oops/objArrayOop.inline.hpp" 38 #include "oops/oop.inline.hpp" 39 #include "prims/methodHandles.hpp" 40 #include "prims/jvmtiRedefineClassesTrace.hpp" 41 #include "runtime/compilationPolicy.hpp" 42 #include "runtime/javaCalls.hpp" 43 #include "runtime/reflection.hpp" 44 #include "runtime/signature.hpp" 45 #include "runtime/stubRoutines.hpp" 46 #include "utilities/exceptions.hpp" 47 48 49 /* 50 * JSR 292 reference implementation: method handles 51 * The JDK 7 reference implementation represented method handle 52 * combinations as chains. Each link in the chain had a "vmentry" 53 * field which pointed at a bit of assembly code which performed 54 * one transformation before dispatching to the next link in the chain. 55 * 56 * The current reference implementation pushes almost all code generation 57 * responsibility to (trusted) Java code. A method handle contains a 58 * pointer to its "LambdaForm", which embodies all details of the method 59 * handle's behavior. The LambdaForm is a normal Java object, managed 60 * by a runtime coded in Java. 61 */ 62 63 bool MethodHandles::_enabled = false; // set true after successful native linkage 64 MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL; 65 66 67 /** 68 * Generates method handle adapters. Returns 'false' if memory allocation 69 * failed and true otherwise. 70 */ 71 bool MethodHandles::generate_adapters() { 72 if (SystemDictionary::MethodHandle_klass() == NULL) { 73 return true; 74 } 75 76 assert(_adapter_code == NULL, "generate only once"); 77 78 ResourceMark rm; 79 TraceTime timer("MethodHandles adapters generation", TraceStartupTime); 80 _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size); 81 if (_adapter_code == NULL) { 82 return false; 83 } 84 85 CodeBuffer code(_adapter_code); 86 MethodHandlesAdapterGenerator g(&code); 87 g.generate(); 88 code.log_section_sizes("MethodHandlesAdapterBlob"); 89 return true; 90 } 91 92 //------------------------------------------------------------------------------ 93 // MethodHandlesAdapterGenerator::generate 94 // 95 void MethodHandlesAdapterGenerator::generate() { 96 // Generate generic method handle adapters. 97 // Generate interpreter entries 98 for (Interpreter::MethodKind mk = Interpreter::method_handle_invoke_FIRST; 99 mk <= Interpreter::method_handle_invoke_LAST; | 1 /* 2 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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/javaClasses.inline.hpp" 27 #include "classfile/stringTable.hpp" 28 #include "code/codeCache.hpp" 29 #include "code/codeCacheExtensions.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 "oops/objArrayOop.inline.hpp" 38 #include "oops/oop.inline.hpp" 39 #include "prims/methodHandles.hpp" 40 #include "prims/jvmtiRedefineClassesTrace.hpp" 41 #include "runtime/compilationPolicy.hpp" 42 #include "runtime/javaCalls.hpp" 43 #include "runtime/logTimer.hpp" 44 #include "runtime/reflection.hpp" 45 #include "runtime/signature.hpp" 46 #include "runtime/stubRoutines.hpp" 47 #include "utilities/exceptions.hpp" 48 49 50 /* 51 * JSR 292 reference implementation: method handles 52 * The JDK 7 reference implementation represented method handle 53 * combinations as chains. Each link in the chain had a "vmentry" 54 * field which pointed at a bit of assembly code which performed 55 * one transformation before dispatching to the next link in the chain. 56 * 57 * The current reference implementation pushes almost all code generation 58 * responsibility to (trusted) Java code. A method handle contains a 59 * pointer to its "LambdaForm", which embodies all details of the method 60 * handle's behavior. The LambdaForm is a normal Java object, managed 61 * by a runtime coded in Java. 62 */ 63 64 bool MethodHandles::_enabled = false; // set true after successful native linkage 65 MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL; 66 67 68 /** 69 * Generates method handle adapters. Returns 'false' if memory allocation 70 * failed and true otherwise. 71 */ 72 bool MethodHandles::generate_adapters() { 73 if (SystemDictionary::MethodHandle_klass() == NULL) { 74 return true; 75 } 76 77 assert(_adapter_code == NULL, "generate only once"); 78 79 ResourceMark rm; 80 TraceStartupTime timer("MethodHandles adapters generation"); 81 _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size); 82 if (_adapter_code == NULL) { 83 return false; 84 } 85 86 CodeBuffer code(_adapter_code); 87 MethodHandlesAdapterGenerator g(&code); 88 g.generate(); 89 code.log_section_sizes("MethodHandlesAdapterBlob"); 90 return true; 91 } 92 93 //------------------------------------------------------------------------------ 94 // MethodHandlesAdapterGenerator::generate 95 // 96 void MethodHandlesAdapterGenerator::generate() { 97 // Generate generic method handle adapters. 98 // Generate interpreter entries 99 for (Interpreter::MethodKind mk = Interpreter::method_handle_invoke_FIRST; 100 mk <= Interpreter::method_handle_invoke_LAST; |