src/share/vm/shark/sharkCompiler.hpp

Wed, 11 Aug 2010 05:51:21 -0700

author
twisti
date
Wed, 11 Aug 2010 05:51:21 -0700
changeset 2047
d2ede61b7a12
child 2200
a222fcfba398
permissions
-rw-r--r--

6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

     1 /*
     2  * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright 2008, 2009 Red Hat, Inc.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 class SharkContext;
    28 class SharkCompiler : public AbstractCompiler {
    29  public:
    30   // Creation
    31   SharkCompiler();
    33   // Name of this compiler
    34   const char *name()     { return "shark"; }
    36   // Missing feature tests
    37   bool supports_native() { return true; }
    38   bool supports_osr()    { return true; }
    40   // Customization
    41   bool needs_adapters()  { return false; }
    42   bool needs_stubs()     { return false; }
    44   // Initialization
    45   void initialize();
    47   // Compile a normal (bytecode) method and install it in the VM
    48   void compile_method(ciEnv* env, ciMethod* target, int entry_bci);
    50   // Generate a wrapper for a native (JNI) method
    51   nmethod* generate_native_wrapper(MacroAssembler* masm,
    52                                    methodHandle    target,
    53                                    BasicType*      arg_types,
    54                                    BasicType       return_type);
    56   // Free compiled methods (and native wrappers)
    57   void free_compiled_method(address code);
    59   // Each thread generating IR needs its own context.  The normal
    60   // context is used for bytecode methods, and is protected from
    61   // multiple simultaneous accesses by being restricted to the
    62   // compiler thread.  The native context is used for JNI methods,
    63   // and is protected from multiple simultaneous accesses by the
    64   // adapter handler library lock.
    65  private:
    66   SharkContext* _normal_context;
    67   SharkContext* _native_context;
    69  public:
    70   SharkContext* context() const {
    71     if (JavaThread::current()->is_Compiler_thread()) {
    72       return _normal_context;
    73     }
    74     else {
    75       assert(AdapterHandlerLibrary_lock->owned_by_self(), "should be");
    76       return _native_context;
    77     }
    78   }
    80   // The LLVM execution engine is the JIT we use to generate native
    81   // code.  It is thread safe, but we need to protect it with a lock
    82   // of our own because otherwise LLVM's lock and HotSpot's locks
    83   // interleave and deadlock.  The SharkMemoryManager is not thread
    84   // safe, and is protected by the same lock as the execution engine.
    85  private:
    86   Monitor*               _execution_engine_lock;
    87   SharkMemoryManager*    _memory_manager;
    88   llvm::ExecutionEngine* _execution_engine;
    90  private:
    91   Monitor* execution_engine_lock() const {
    92     return _execution_engine_lock;
    93   }
    94   SharkMemoryManager* memory_manager() const {
    95     assert(execution_engine_lock()->owned_by_self(), "should be");
    96     return _memory_manager;
    97   }
    98   llvm::ExecutionEngine* execution_engine() const {
    99     assert(execution_engine_lock()->owned_by_self(), "should be");
   100     return _execution_engine;
   101   }
   103   // Global access
   104  public:
   105   static SharkCompiler* compiler() {
   106     AbstractCompiler *compiler =
   107       CompileBroker::compiler(CompLevel_fast_compile);
   108     assert(compiler->is_shark() && compiler->is_initialized(), "should be");
   109     return (SharkCompiler *) compiler;
   110   }
   112   // Helpers
   113  private:
   114   static const char* methodname(const char* klass, const char* method);
   115   void generate_native_code(SharkEntry*     entry,
   116                             llvm::Function* function,
   117                             const char*     name);
   118   void free_queued_methods();
   119 };

mercurial