1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkCompiler.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,131 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009, 2010, 2011 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#ifndef SHARE_VM_SHARK_SHARKCOMPILER_HPP 1.30 +#define SHARE_VM_SHARK_SHARKCOMPILER_HPP 1.31 + 1.32 +#include "ci/ciEnv.hpp" 1.33 +#include "ci/ciMethod.hpp" 1.34 +#include "compiler/abstractCompiler.hpp" 1.35 +#include "compiler/compileBroker.hpp" 1.36 +#include "shark/llvmHeaders.hpp" 1.37 +#include "shark/sharkMemoryManager.hpp" 1.38 + 1.39 +class SharkContext; 1.40 + 1.41 +class SharkCompiler : public AbstractCompiler { 1.42 + public: 1.43 + // Creation 1.44 + SharkCompiler(); 1.45 + 1.46 + // Name of this compiler 1.47 + const char *name() { return "shark"; } 1.48 + 1.49 + // Missing feature tests 1.50 + bool supports_native() { return true; } 1.51 + bool supports_osr() { return true; } 1.52 + bool can_compile_method(methodHandle method) { 1.53 + return ! (method->is_method_handle_intrinsic() || method->is_compiled_lambda_form()); 1.54 + } 1.55 + 1.56 + // Initialization 1.57 + void initialize(); 1.58 + 1.59 + // Compile a normal (bytecode) method and install it in the VM 1.60 + void compile_method(ciEnv* env, ciMethod* target, int entry_bci); 1.61 + 1.62 + // Generate a wrapper for a native (JNI) method 1.63 + nmethod* generate_native_wrapper(MacroAssembler* masm, 1.64 + methodHandle target, 1.65 + int compile_id, 1.66 + BasicType* arg_types, 1.67 + BasicType return_type); 1.68 + 1.69 + // Free compiled methods (and native wrappers) 1.70 + void free_compiled_method(address code); 1.71 + 1.72 + // Each thread generating IR needs its own context. The normal 1.73 + // context is used for bytecode methods, and is protected from 1.74 + // multiple simultaneous accesses by being restricted to the 1.75 + // compiler thread. The native context is used for JNI methods, 1.76 + // and is protected from multiple simultaneous accesses by the 1.77 + // adapter handler library lock. 1.78 + private: 1.79 + SharkContext* _normal_context; 1.80 + SharkContext* _native_context; 1.81 + 1.82 + public: 1.83 + SharkContext* context() const { 1.84 + if (JavaThread::current()->is_Compiler_thread()) { 1.85 + return _normal_context; 1.86 + } 1.87 + else { 1.88 + assert(AdapterHandlerLibrary_lock->owned_by_self(), "should be"); 1.89 + return _native_context; 1.90 + } 1.91 + } 1.92 + 1.93 + // The LLVM execution engine is the JIT we use to generate native 1.94 + // code. It is thread safe, but we need to protect it with a lock 1.95 + // of our own because otherwise LLVM's lock and HotSpot's locks 1.96 + // interleave and deadlock. The SharkMemoryManager is not thread 1.97 + // safe, and is protected by the same lock as the execution engine. 1.98 + private: 1.99 + Monitor* _execution_engine_lock; 1.100 + SharkMemoryManager* _memory_manager; 1.101 + llvm::ExecutionEngine* _execution_engine; 1.102 + 1.103 + private: 1.104 + Monitor* execution_engine_lock() const { 1.105 + return _execution_engine_lock; 1.106 + } 1.107 + SharkMemoryManager* memory_manager() const { 1.108 + assert(execution_engine_lock()->owned_by_self(), "should be"); 1.109 + return _memory_manager; 1.110 + } 1.111 + llvm::ExecutionEngine* execution_engine() const { 1.112 + assert(execution_engine_lock()->owned_by_self(), "should be"); 1.113 + return _execution_engine; 1.114 + } 1.115 + 1.116 + // Global access 1.117 + public: 1.118 + static SharkCompiler* compiler() { 1.119 + AbstractCompiler *compiler = 1.120 + CompileBroker::compiler(CompLevel_full_optimization); 1.121 + assert(compiler->is_shark() && compiler->is_initialized(), "should be"); 1.122 + return (SharkCompiler *) compiler; 1.123 + } 1.124 + 1.125 + // Helpers 1.126 + private: 1.127 + static const char* methodname(const char* klass, const char* method); 1.128 + void generate_native_code(SharkEntry* entry, 1.129 + llvm::Function* function, 1.130 + const char* name); 1.131 + void free_queued_methods(); 1.132 +}; 1.133 + 1.134 +#endif // SHARE_VM_SHARK_SHARKCOMPILER_HPP