src/share/vm/shark/sharkCompiler.hpp

Fri, 08 Oct 2010 02:42:17 -0700

author
twisti
date
Fri, 08 Oct 2010 02:42:17 -0700
changeset 2200
a222fcfba398
parent 2047
d2ede61b7a12
child 2314
f95d63e2154a
permissions
-rw-r--r--

6990549: Zero and Shark fixes after 6978355 and 6953144
Reviewed-by: twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

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

mercurial