70 fatal("llvm_start_multithreaded() failed"); |
68 fatal("llvm_start_multithreaded() failed"); |
71 |
69 |
72 // Initialize the native target |
70 // Initialize the native target |
73 InitializeNativeTarget(); |
71 InitializeNativeTarget(); |
74 |
72 |
|
73 // MCJIT require a native AsmPrinter |
|
74 InitializeNativeTargetAsmPrinter(); |
|
75 |
75 // Create the two contexts which we'll use |
76 // Create the two contexts which we'll use |
76 _normal_context = new SharkContext("normal"); |
77 _normal_context = new SharkContext("normal"); |
77 _native_context = new SharkContext("native"); |
78 _native_context = new SharkContext("native"); |
78 |
79 |
79 // Create the memory manager |
80 // Create the memory manager |
80 _memory_manager = new SharkMemoryManager(); |
81 _memory_manager = new SharkMemoryManager(); |
81 |
82 |
82 #if SHARK_LLVM_VERSION >= 27 |
|
83 // Finetune LLVM for the current host CPU. |
83 // Finetune LLVM for the current host CPU. |
84 StringMap<bool> Features; |
84 StringMap<bool> Features; |
85 bool gotCpuFeatures = llvm::sys::getHostCPUFeatures(Features); |
85 bool gotCpuFeatures = llvm::sys::getHostCPUFeatures(Features); |
86 std::string cpu("-mcpu=" + llvm::sys::getHostCPUName()); |
86 std::string cpu("-mcpu=" + llvm::sys::getHostCPUName()); |
87 |
87 |
111 builder.setMCPU(MCPU); |
111 builder.setMCPU(MCPU); |
112 builder.setMAttrs(MAttrs); |
112 builder.setMAttrs(MAttrs); |
113 builder.setJITMemoryManager(memory_manager()); |
113 builder.setJITMemoryManager(memory_manager()); |
114 builder.setEngineKind(EngineKind::JIT); |
114 builder.setEngineKind(EngineKind::JIT); |
115 builder.setErrorStr(&ErrorMsg); |
115 builder.setErrorStr(&ErrorMsg); |
|
116 if (! fnmatch(SharkOptimizationLevel, "None", 0)) { |
|
117 tty->print_cr("Shark optimization level set to: None"); |
|
118 builder.setOptLevel(llvm::CodeGenOpt::None); |
|
119 } else if (! fnmatch(SharkOptimizationLevel, "Less", 0)) { |
|
120 tty->print_cr("Shark optimization level set to: Less"); |
|
121 builder.setOptLevel(llvm::CodeGenOpt::Less); |
|
122 } else if (! fnmatch(SharkOptimizationLevel, "Aggressive", 0)) { |
|
123 tty->print_cr("Shark optimization level set to: Aggressive"); |
|
124 builder.setOptLevel(llvm::CodeGenOpt::Aggressive); |
|
125 } // else Default is selected by, well, default :-) |
116 _execution_engine = builder.create(); |
126 _execution_engine = builder.create(); |
117 |
127 |
118 if (!execution_engine()) { |
128 if (!execution_engine()) { |
119 if (!ErrorMsg.empty()) |
129 if (!ErrorMsg.empty()) |
120 printf("Error while creating Shark JIT: %s\n",ErrorMsg.c_str()); |
130 printf("Error while creating Shark JIT: %s\n",ErrorMsg.c_str()); |
259 if (SharkPrintBitcodeOf != NULL) { |
262 if (SharkPrintBitcodeOf != NULL) { |
260 if (!fnmatch(SharkPrintBitcodeOf, name, 0)) |
263 if (!fnmatch(SharkPrintBitcodeOf, name, 0)) |
261 function->dump(); |
264 function->dump(); |
262 } |
265 } |
263 |
266 |
|
267 if (SharkVerifyFunction != NULL) { |
|
268 if (!fnmatch(SharkVerifyFunction, name, 0)) { |
|
269 verifyFunction(*function); |
|
270 } |
|
271 } |
|
272 |
264 // Compile to native code |
273 // Compile to native code |
265 address code = NULL; |
274 address code = NULL; |
266 context()->add_function(function); |
275 context()->add_function(function); |
267 { |
276 { |
268 MutexLocker locker(execution_engine_lock()); |
277 MutexLocker locker(execution_engine_lock()); |
269 free_queued_methods(); |
278 free_queued_methods(); |
270 |
279 |
|
280 #ifndef NDEBUG |
|
281 #if SHARK_LLVM_VERSION <= 31 |
|
282 #define setCurrentDebugType SetCurrentDebugType |
|
283 #endif |
271 if (SharkPrintAsmOf != NULL) { |
284 if (SharkPrintAsmOf != NULL) { |
272 #if SHARK_LLVM_VERSION >= 27 |
|
273 #ifndef NDEBUG |
|
274 if (!fnmatch(SharkPrintAsmOf, name, 0)) { |
285 if (!fnmatch(SharkPrintAsmOf, name, 0)) { |
275 llvm::SetCurrentDebugType(X86_ONLY("x86-emitter") NOT_X86("jit")); |
286 llvm::setCurrentDebugType(X86_ONLY("x86-emitter") NOT_X86("jit")); |
276 llvm::DebugFlag = true; |
287 llvm::DebugFlag = true; |
277 } |
288 } |
278 else { |
289 else { |
279 llvm::SetCurrentDebugType(""); |
290 llvm::setCurrentDebugType(""); |
280 llvm::DebugFlag = false; |
291 llvm::DebugFlag = false; |
281 } |
292 } |
|
293 } |
|
294 #ifdef setCurrentDebugType |
|
295 #undef setCurrentDebugType |
|
296 #endif |
282 #endif // !NDEBUG |
297 #endif // !NDEBUG |
283 #else |
|
284 // NB you need to patch LLVM with http://tinyurl.com/yf3baln for this |
|
285 std::vector<const char*> args; |
|
286 args.push_back(""); // program name |
|
287 if (!fnmatch(SharkPrintAsmOf, name, 0)) |
|
288 args.push_back("-debug-only=x86-emitter"); |
|
289 else |
|
290 args.push_back("-debug-only=none"); |
|
291 args.push_back(0); // terminator |
|
292 cl::ParseCommandLineOptions(args.size() - 1, (char **) &args[0]); |
|
293 #endif // SHARK_LLVM_VERSION |
|
294 } |
|
295 memory_manager()->set_entry_for_function(function, entry); |
298 memory_manager()->set_entry_for_function(function, entry); |
296 code = (address) execution_engine()->getPointerToFunction(function); |
299 code = (address) execution_engine()->getPointerToFunction(function); |
297 } |
300 } |
|
301 assert(code != NULL, "code must be != NULL"); |
298 entry->set_entry_point(code); |
302 entry->set_entry_point(code); |
299 entry->set_function(function); |
303 entry->set_function(function); |
300 entry->set_context(context()); |
304 entry->set_context(context()); |
301 address code_start = entry->code_start(); |
305 address code_start = entry->code_start(); |
302 address code_limit = entry->code_limit(); |
306 address code_limit = entry->code_limit(); |
317 // This method may only be called when the VM is at a safepoint. |
321 // This method may only be called when the VM is at a safepoint. |
318 // All _thread_in_vm threads will be waiting for the safepoint to |
322 // All _thread_in_vm threads will be waiting for the safepoint to |
319 // finish with the exception of the VM thread, so we can consider |
323 // finish with the exception of the VM thread, so we can consider |
320 // ourself the owner of the execution engine lock even though we |
324 // ourself the owner of the execution engine lock even though we |
321 // can't actually acquire it at this time. |
325 // can't actually acquire it at this time. |
322 assert(Thread::current()->is_VM_thread(), "must be called by VM thread"); |
326 assert(Thread::current()->is_Compiler_thread(), "must be called by compiler thread"); |
323 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
327 assert_locked_or_safepoint(CodeCache_lock); |
324 |
328 |
325 SharkEntry *entry = (SharkEntry *) code; |
329 SharkEntry *entry = (SharkEntry *) code; |
326 entry->context()->push_to_free_queue(entry->function()); |
330 entry->context()->push_to_free_queue(entry->function()); |
327 } |
331 } |
328 |
332 |