Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkCompiler.hpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* Copyright 2008, 2009, 2010, 2011 Red Hat, Inc.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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#ifndef SHARE_VM_SHARK_SHARKCOMPILER_HPP26#define SHARE_VM_SHARK_SHARKCOMPILER_HPP2728#include "ci/ciEnv.hpp"29#include "ci/ciMethod.hpp"30#include "compiler/abstractCompiler.hpp"31#include "compiler/compileBroker.hpp"32#include "shark/llvmHeaders.hpp"33#include "shark/sharkMemoryManager.hpp"3435class SharkContext;3637class SharkCompiler : public AbstractCompiler {38public:39// Creation40SharkCompiler();4142// Name of this compiler43const char *name() { return "shark"; }4445// Missing feature tests46bool supports_native() { return true; }47bool supports_osr() { return true; }48bool can_compile_method(methodHandle method) {49return ! (method->is_method_handle_intrinsic() || method->is_compiled_lambda_form());50}5152// Initialization53void initialize();5455// Compile a normal (bytecode) method and install it in the VM56void compile_method(ciEnv* env, ciMethod* target, int entry_bci);5758// Generate a wrapper for a native (JNI) method59nmethod* generate_native_wrapper(MacroAssembler* masm,60methodHandle target,61int compile_id,62BasicType* arg_types,63BasicType return_type);6465// Free compiled methods (and native wrappers)66void free_compiled_method(address code);6768// Each thread generating IR needs its own context. The normal69// context is used for bytecode methods, and is protected from70// multiple simultaneous accesses by being restricted to the71// compiler thread. The native context is used for JNI methods,72// and is protected from multiple simultaneous accesses by the73// adapter handler library lock.74private:75SharkContext* _normal_context;76SharkContext* _native_context;7778public:79SharkContext* context() const {80if (JavaThread::current()->is_Compiler_thread()) {81return _normal_context;82}83else {84assert(AdapterHandlerLibrary_lock->owned_by_self(), "should be");85return _native_context;86}87}8889// The LLVM execution engine is the JIT we use to generate native90// code. It is thread safe, but we need to protect it with a lock91// of our own because otherwise LLVM's lock and HotSpot's locks92// interleave and deadlock. The SharkMemoryManager is not thread93// safe, and is protected by the same lock as the execution engine.94private:95Monitor* _execution_engine_lock;96SharkMemoryManager* _memory_manager;97llvm::ExecutionEngine* _execution_engine;9899private:100Monitor* execution_engine_lock() const {101return _execution_engine_lock;102}103SharkMemoryManager* memory_manager() const {104assert(execution_engine_lock()->owned_by_self(), "should be");105return _memory_manager;106}107llvm::ExecutionEngine* execution_engine() const {108assert(execution_engine_lock()->owned_by_self(), "should be");109return _execution_engine;110}111112// Global access113public:114static SharkCompiler* compiler() {115AbstractCompiler *compiler =116CompileBroker::compiler(CompLevel_full_optimization);117assert(compiler->is_shark() && compiler->is_initialized(), "should be");118return (SharkCompiler *) compiler;119}120121// Helpers122private:123static const char* methodname(const char* klass, const char* method);124void generate_native_code(SharkEntry* entry,125llvm::Function* function,126const char* name);127void free_queued_methods();128};129130#endif // SHARE_VM_SHARK_SHARKCOMPILER_HPP131132133