src/share/vm/shark/sharkCompiler.cpp
Print this page
rev 3810 : [mq]: shark.patch
@@ -46,20 +46,18 @@
#include <fnmatch.h>
using namespace llvm;
-#if SHARK_LLVM_VERSION >= 27
namespace {
cl::opt<std::string>
MCPU("mcpu");
cl::list<std::string>
MAttrs("mattr",
cl::CommaSeparated);
}
-#endif
SharkCompiler::SharkCompiler()
: AbstractCompiler() {
// Create the lock to protect the memory manager and execution engine
_execution_engine_lock = new Monitor(Mutex::leaf, "SharkExecutionEngineLock");
@@ -70,18 +68,20 @@
fatal("llvm_start_multithreaded() failed");
// Initialize the native target
InitializeNativeTarget();
+ // MCJIT require a native AsmPrinter
+ InitializeNativeTargetAsmPrinter();
+
// Create the two contexts which we'll use
_normal_context = new SharkContext("normal");
_native_context = new SharkContext("native");
// Create the memory manager
_memory_manager = new SharkMemoryManager();
-#if SHARK_LLVM_VERSION >= 27
// Finetune LLVM for the current host CPU.
StringMap<bool> Features;
bool gotCpuFeatures = llvm::sys::getHostCPUFeatures(Features);
std::string cpu("-mcpu=" + llvm::sys::getHostCPUName());
@@ -123,17 +123,10 @@
exit(1);
}
execution_engine()->addModule(
_native_context->module());
-#else
- _execution_engine = ExecutionEngine::createJIT(
- _normal_context->module_provider(),
- NULL, memory_manager(), CodeGenOpt::Default);
- execution_engine()->addModuleProvider(
- _native_context->module_provider());
-#endif
// All done
mark_initialized();
}
@@ -147,10 +140,14 @@
assert(is_initialized(), "should be");
ResourceMark rm;
const char *name = methodname(
target->holder()->name()->as_utf8(), target->name()->as_utf8());
+ if (SharkShowCompiledMethods) {
+ tty->print_cr("Shark compiling method: %s", name);
+ }
+
// Do the typeflow analysis
ciTypeFlow *flow;
if (entry_bci == InvocationEntryBci)
flow = target->get_flow_analysis();
else
@@ -180,10 +177,13 @@
// Emit the entry point
SharkEntry *entry = (SharkEntry *) cb.malloc(sizeof(SharkEntry));
// Build the LLVM IR for the method
Function *function = SharkFunction::build(env, &builder, flow, name);
+ if (SharkVerifyFunctions) {
+ verifyFunction(*function);
+ }
// Generate native code. It's unpleasant that we have to drop into
// the VM to do this -- it blocks safepoints -- but I can't see any
// other way to handle the locking.
{
@@ -267,36 +267,25 @@
{
MutexLocker locker(execution_engine_lock());
free_queued_methods();
if (SharkPrintAsmOf != NULL) {
-#if SHARK_LLVM_VERSION >= 27
#ifndef NDEBUG
if (!fnmatch(SharkPrintAsmOf, name, 0)) {
llvm::SetCurrentDebugType(X86_ONLY("x86-emitter") NOT_X86("jit"));
llvm::DebugFlag = true;
}
else {
llvm::SetCurrentDebugType("");
llvm::DebugFlag = false;
}
#endif // !NDEBUG
-#else
- // NB you need to patch LLVM with http://tinyurl.com/yf3baln for this
- std::vector<const char*> args;
- args.push_back(""); // program name
- if (!fnmatch(SharkPrintAsmOf, name, 0))
- args.push_back("-debug-only=x86-emitter");
- else
- args.push_back("-debug-only=none");
- args.push_back(0); // terminator
- cl::ParseCommandLineOptions(args.size() - 1, (char **) &args[0]);
-#endif // SHARK_LLVM_VERSION
}
memory_manager()->set_entry_for_function(function, entry);
code = (address) execution_engine()->getPointerToFunction(function);
}
+ assert(code != NULL, "code must be != NULL");
entry->set_entry_point(code);
entry->set_function(function);
entry->set_context(context());
address code_start = entry->code_start();
address code_limit = entry->code_limit();
@@ -317,12 +306,12 @@
// This method may only be called when the VM is at a safepoint.
// All _thread_in_vm threads will be waiting for the safepoint to
// finish with the exception of the VM thread, so we can consider
// ourself the owner of the execution engine lock even though we
// can't actually acquire it at this time.
- assert(Thread::current()->is_VM_thread(), "must be called by VM thread");
- assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
+ assert(Thread::current()->is_Compiler_thread(), "must be called by compiler thread");
+ assert_locked_or_safepoint(CodeCache_lock);
SharkEntry *entry = (SharkEntry *) code;
entry->context()->push_to_free_queue(entry->function());
}