src/share/vm/shark/sharkCompiler.cpp

Print this page
rev 3850 : [mq]: shark.patch

*** 46,65 **** #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"); --- 46,63 ----
*** 70,87 **** fatal("llvm_start_multithreaded() failed"); // Initialize the native target InitializeNativeTarget(); // 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()); --- 68,87 ---- 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(); // Finetune LLVM for the current host CPU. StringMap<bool> Features; bool gotCpuFeatures = llvm::sys::getHostCPUFeatures(Features); std::string cpu("-mcpu=" + llvm::sys::getHostCPUName());
*** 111,120 **** --- 111,130 ---- builder.setMCPU(MCPU); builder.setMAttrs(MAttrs); builder.setJITMemoryManager(memory_manager()); builder.setEngineKind(EngineKind::JIT); builder.setErrorStr(&ErrorMsg); + if (! fnmatch(SharkOptimizationLevel, "None", 0)) { + tty->print_cr("Shark optimization level set to: None"); + builder.setOptLevel(llvm::CodeGenOpt::None); + } else if (! fnmatch(SharkOptimizationLevel, "Less", 0)) { + tty->print_cr("Shark optimization level set to: Less"); + builder.setOptLevel(llvm::CodeGenOpt::Less); + } else if (! fnmatch(SharkOptimizationLevel, "Aggressive", 0)) { + tty->print_cr("Shark optimization level set to: Aggressive"); + builder.setOptLevel(llvm::CodeGenOpt::Aggressive); + } // else Default is selected by, well, default :-) _execution_engine = builder.create(); if (!execution_engine()) { if (!ErrorMsg.empty()) printf("Error while creating Shark JIT: %s\n",ErrorMsg.c_str());
*** 123,139 **** 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(); } --- 133,142 ----
*** 259,302 **** if (SharkPrintBitcodeOf != NULL) { if (!fnmatch(SharkPrintBitcodeOf, name, 0)) function->dump(); } // Compile to native code address code = NULL; context()->add_function(function); { 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); } 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(); --- 262,306 ---- if (SharkPrintBitcodeOf != NULL) { if (!fnmatch(SharkPrintBitcodeOf, name, 0)) function->dump(); } + if (SharkVerifyFunction != NULL) { + if (!fnmatch(SharkVerifyFunction, name, 0)) { + verifyFunction(*function); + } + } + // Compile to native code address code = NULL; context()->add_function(function); { MutexLocker locker(execution_engine_lock()); free_queued_methods(); #ifndef NDEBUG + #if SHARK_LLVM_VERSION <= 31 + #define setCurrentDebugType SetCurrentDebugType + #endif + if (SharkPrintAsmOf != NULL) { if (!fnmatch(SharkPrintAsmOf, name, 0)) { ! llvm::setCurrentDebugType(X86_ONLY("x86-emitter") NOT_X86("jit")); llvm::DebugFlag = true; } else { ! llvm::setCurrentDebugType(""); llvm::DebugFlag = false; } } + #ifdef setCurrentDebugType + #undef setCurrentDebugType + #endif + #endif // !NDEBUG 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,328 **** // 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"); SharkEntry *entry = (SharkEntry *) code; entry->context()->push_to_free_queue(entry->function()); } --- 321,332 ---- // 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_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()); }