src/share/vm/shark/sharkCompiler.cpp

changeset 4314
2cd5e15048e6
parent 2729
e863062e521d
child 4443
c095a7f289aa
     1.1 --- a/src/share/vm/shark/sharkCompiler.cpp	Mon Nov 26 17:25:11 2012 -0800
     1.2 +++ b/src/share/vm/shark/sharkCompiler.cpp	Tue Nov 27 12:48:52 2012 -0800
     1.3 @@ -48,7 +48,6 @@
     1.4  
     1.5  using namespace llvm;
     1.6  
     1.7 -#if SHARK_LLVM_VERSION >= 27
     1.8  namespace {
     1.9    cl::opt<std::string>
    1.10    MCPU("mcpu");
    1.11 @@ -57,7 +56,6 @@
    1.12    MAttrs("mattr",
    1.13           cl::CommaSeparated);
    1.14  }
    1.15 -#endif
    1.16  
    1.17  SharkCompiler::SharkCompiler()
    1.18    : AbstractCompiler() {
    1.19 @@ -72,6 +70,9 @@
    1.20    // Initialize the native target
    1.21    InitializeNativeTarget();
    1.22  
    1.23 +  // MCJIT require a native AsmPrinter
    1.24 +  InitializeNativeTargetAsmPrinter();
    1.25 +
    1.26    // Create the two contexts which we'll use
    1.27    _normal_context = new SharkContext("normal");
    1.28    _native_context = new SharkContext("native");
    1.29 @@ -79,7 +80,6 @@
    1.30    // Create the memory manager
    1.31    _memory_manager = new SharkMemoryManager();
    1.32  
    1.33 -#if SHARK_LLVM_VERSION >= 27
    1.34    // Finetune LLVM for the current host CPU.
    1.35    StringMap<bool> Features;
    1.36    bool gotCpuFeatures = llvm::sys::getHostCPUFeatures(Features);
    1.37 @@ -113,6 +113,16 @@
    1.38    builder.setJITMemoryManager(memory_manager());
    1.39    builder.setEngineKind(EngineKind::JIT);
    1.40    builder.setErrorStr(&ErrorMsg);
    1.41 +  if (! fnmatch(SharkOptimizationLevel, "None", 0)) {
    1.42 +    tty->print_cr("Shark optimization level set to: None");
    1.43 +    builder.setOptLevel(llvm::CodeGenOpt::None);
    1.44 +  } else if (! fnmatch(SharkOptimizationLevel, "Less", 0)) {
    1.45 +    tty->print_cr("Shark optimization level set to: Less");
    1.46 +    builder.setOptLevel(llvm::CodeGenOpt::Less);
    1.47 +  } else if (! fnmatch(SharkOptimizationLevel, "Aggressive", 0)) {
    1.48 +    tty->print_cr("Shark optimization level set to: Aggressive");
    1.49 +    builder.setOptLevel(llvm::CodeGenOpt::Aggressive);
    1.50 +  } // else Default is selected by, well, default :-)
    1.51    _execution_engine = builder.create();
    1.52  
    1.53    if (!execution_engine()) {
    1.54 @@ -125,13 +135,6 @@
    1.55  
    1.56    execution_engine()->addModule(
    1.57      _native_context->module());
    1.58 -#else
    1.59 -  _execution_engine = ExecutionEngine::createJIT(
    1.60 -    _normal_context->module_provider(),
    1.61 -    NULL, memory_manager(), CodeGenOpt::Default);
    1.62 -  execution_engine()->addModuleProvider(
    1.63 -    _native_context->module_provider());
    1.64 -#endif
    1.65  
    1.66    // All done
    1.67    mark_initialized();
    1.68 @@ -261,6 +264,12 @@
    1.69        function->dump();
    1.70    }
    1.71  
    1.72 +  if (SharkVerifyFunction != NULL) {
    1.73 +    if (!fnmatch(SharkVerifyFunction, name, 0)) {
    1.74 +      verifyFunction(*function);
    1.75 +    }
    1.76 +  }
    1.77 +
    1.78    // Compile to native code
    1.79    address code = NULL;
    1.80    context()->add_function(function);
    1.81 @@ -268,33 +277,28 @@
    1.82      MutexLocker locker(execution_engine_lock());
    1.83      free_queued_methods();
    1.84  
    1.85 +#ifndef NDEBUG
    1.86 +#if SHARK_LLVM_VERSION <= 31
    1.87 +#define setCurrentDebugType SetCurrentDebugType
    1.88 +#endif
    1.89      if (SharkPrintAsmOf != NULL) {
    1.90 -#if SHARK_LLVM_VERSION >= 27
    1.91 -#ifndef NDEBUG
    1.92        if (!fnmatch(SharkPrintAsmOf, name, 0)) {
    1.93 -        llvm::SetCurrentDebugType(X86_ONLY("x86-emitter") NOT_X86("jit"));
    1.94 +        llvm::setCurrentDebugType(X86_ONLY("x86-emitter") NOT_X86("jit"));
    1.95          llvm::DebugFlag = true;
    1.96        }
    1.97        else {
    1.98 -        llvm::SetCurrentDebugType("");
    1.99 +        llvm::setCurrentDebugType("");
   1.100          llvm::DebugFlag = false;
   1.101        }
   1.102 +    }
   1.103 +#ifdef setCurrentDebugType
   1.104 +#undef setCurrentDebugType
   1.105 +#endif
   1.106  #endif // !NDEBUG
   1.107 -#else
   1.108 -      // NB you need to patch LLVM with http://tinyurl.com/yf3baln for this
   1.109 -      std::vector<const char*> args;
   1.110 -      args.push_back(""); // program name
   1.111 -      if (!fnmatch(SharkPrintAsmOf, name, 0))
   1.112 -        args.push_back("-debug-only=x86-emitter");
   1.113 -      else
   1.114 -        args.push_back("-debug-only=none");
   1.115 -      args.push_back(0);  // terminator
   1.116 -      cl::ParseCommandLineOptions(args.size() - 1, (char **) &args[0]);
   1.117 -#endif // SHARK_LLVM_VERSION
   1.118 -    }
   1.119      memory_manager()->set_entry_for_function(function, entry);
   1.120      code = (address) execution_engine()->getPointerToFunction(function);
   1.121    }
   1.122 +  assert(code != NULL, "code must be != NULL");
   1.123    entry->set_entry_point(code);
   1.124    entry->set_function(function);
   1.125    entry->set_context(context());
   1.126 @@ -319,8 +323,8 @@
   1.127    // finish with the exception of the VM thread, so we can consider
   1.128    // ourself the owner of the execution engine lock even though we
   1.129    // can't actually acquire it at this time.
   1.130 -  assert(Thread::current()->is_VM_thread(), "must be called by VM thread");
   1.131 -  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
   1.132 +  assert(Thread::current()->is_Compiler_thread(), "must be called by compiler thread");
   1.133 +  assert_locked_or_safepoint(CodeCache_lock);
   1.134  
   1.135    SharkEntry *entry = (SharkEntry *) code;
   1.136    entry->context()->push_to_free_queue(entry->function());

mercurial