< prev index next >

src/share/vm/shark/sharkCompiler.cpp

Print this page
rev 7614 : [mq]: shark-build-hotspot.patch


  44 #include "shark/shark_globals.hpp"
  45 #include "utilities/debug.hpp"
  46 
  47 #include <fnmatch.h>
  48 
  49 using namespace llvm;
  50 
  51 namespace {
  52   cl::opt<std::string>
  53   MCPU("mcpu");
  54 
  55   cl::list<std::string>
  56   MAttrs("mattr",
  57          cl::CommaSeparated);
  58 }
  59 
  60 SharkCompiler::SharkCompiler()
  61   : AbstractCompiler(shark) {
  62   // Create the lock to protect the memory manager and execution engine
  63   _execution_engine_lock = new Monitor(Mutex::leaf, "SharkExecutionEngineLock");

  64   MutexLocker locker(execution_engine_lock());







  65 
  66   // Make LLVM safe for multithreading
  67   if (!llvm_start_multithreaded())
  68     fatal("llvm_start_multithreaded() failed");
  69 
  70   // Initialize the native target
  71   InitializeNativeTarget();
  72 
  73   // MCJIT require a native AsmPrinter
  74   InitializeNativeTargetAsmPrinter();
  75 
  76   // Create the two contexts which we'll use
  77   _normal_context = new SharkContext("normal");
  78   _native_context = new SharkContext("native");
  79 
  80   // Create the memory manager
  81   _memory_manager = new SharkMemoryManager();
  82 
  83   // Finetune LLVM for the current host CPU.
  84   StringMap<bool> Features;


 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 :-)
 126   _execution_engine = builder.create();
 127 
 128   if (!execution_engine()) {
 129     if (!ErrorMsg.empty())
 130       printf("Error while creating Shark JIT: %s\n",ErrorMsg.c_str());
 131     else
 132       printf("Unknown error while creating Shark JIT\n");
 133     exit(1);
 134   }
 135 
 136   execution_engine()->addModule(_native_context->module());
 137 
 138   // All done
 139   set_state(initialized);
 140 }
 141 
 142 void SharkCompiler::initialize() {
 143   ShouldNotCallThis();
 144 }
 145 
 146 void SharkCompiler::compile_method(ciEnv*    env,
 147                                    ciMethod* target,
 148                                    int       entry_bci) {
 149   assert(is_initialized(), "should be");
 150   ResourceMark rm;
 151   const char *name = methodname(
 152     target->holder()->name()->as_utf8(), target->name()->as_utf8());
 153 
 154   // Do the typeflow analysis
 155   ciTypeFlow *flow;
 156   if (entry_bci == InvocationEntryBci)
 157     flow = target->get_flow_analysis();
 158   else
 159     flow = target->get_osr_flow_analysis(entry_bci);
 160   if (flow->failing())
 161     return;
 162   if (SharkPrintTypeflowOf != NULL) {
 163     if (!fnmatch(SharkPrintTypeflowOf, name, 0))
 164       flow->print_on(tty);
 165   }
 166 
 167   // Create the recorders
 168   Arena arena;
 169   env->set_oop_recorder(new OopRecorder(&arena));
 170   OopMapSet oopmaps;
 171   env->set_debug_info(new DebugInformationRecorder(env->oop_recorder()));
 172   env->debug_info()->set_oopmaps(&oopmaps);
 173   env->set_dependencies(new Dependencies(env));
 174 
 175   // Create the code buffer and builder
 176   CodeBuffer hscb("Shark", 256 * K, 64 * K);
 177   hscb.initialize_oop_recorder(env->oop_recorder());
 178   MacroAssembler *masm = new MacroAssembler(&hscb);
 179   SharkCodeBuffer cb(masm);
 180   SharkBuilder builder(&cb);
 181 
 182   // Emit the entry point
 183   SharkEntry *entry = (SharkEntry *) cb.malloc(sizeof(SharkEntry));
 184 
 185   // Build the LLVM IR for the method
 186   Function *function = SharkFunction::build(env, &builder, flow, name);
 187   if (env->failing()) {
 188     return;




  44 #include "shark/shark_globals.hpp"
  45 #include "utilities/debug.hpp"
  46 
  47 #include <fnmatch.h>
  48 
  49 using namespace llvm;
  50 
  51 namespace {
  52   cl::opt<std::string>
  53   MCPU("mcpu");
  54 
  55   cl::list<std::string>
  56   MAttrs("mattr",
  57          cl::CommaSeparated);
  58 }
  59 
  60 SharkCompiler::SharkCompiler()
  61   : AbstractCompiler(shark) {
  62   // Create the lock to protect the memory manager and execution engine
  63   _execution_engine_lock = new Monitor(Mutex::leaf, "SharkExecutionEngineLock");
  64   {
  65     MutexLocker locker(execution_engine_lock());
  66     init_llvm();
  67   }
  68   // All done
  69   set_state(initialized);
  70 }
  71 
  72 void SharkCompiler::init_llvm() {
  73 
  74   // Make LLVM safe for multithreading
  75   if (!llvm_start_multithreaded())
  76     fatal("llvm_start_multithreaded() failed");
  77 
  78   // Initialize the native target
  79   InitializeNativeTarget();
  80 
  81   // MCJIT require a native AsmPrinter
  82   InitializeNativeTargetAsmPrinter();
  83 
  84   // Create the two contexts which we'll use
  85   _normal_context = new SharkContext("normal");
  86   _native_context = new SharkContext("native");
  87 
  88   // Create the memory manager
  89   _memory_manager = new SharkMemoryManager();
  90 
  91   // Finetune LLVM for the current host CPU.
  92   StringMap<bool> Features;


 125     tty->print_cr("Shark optimization level set to: None");
 126     builder.setOptLevel(llvm::CodeGenOpt::None);
 127   } else if (! fnmatch(SharkOptimizationLevel, "Less", 0)) {
 128     tty->print_cr("Shark optimization level set to: Less");
 129     builder.setOptLevel(llvm::CodeGenOpt::Less);
 130   } else if (! fnmatch(SharkOptimizationLevel, "Aggressive", 0)) {
 131     tty->print_cr("Shark optimization level set to: Aggressive");
 132     builder.setOptLevel(llvm::CodeGenOpt::Aggressive);
 133   } // else Default is selected by, well, default :-)
 134   _execution_engine = builder.create();
 135 
 136   if (!execution_engine()) {
 137     if (!ErrorMsg.empty())
 138       printf("Error while creating Shark JIT: %s\n",ErrorMsg.c_str());
 139     else
 140       printf("Unknown error while creating Shark JIT\n");
 141     exit(1);
 142   }
 143 
 144   execution_engine()->addModule(_native_context->module());



 145 }
 146 
 147 void SharkCompiler::initialize() {
 148   ShouldNotCallThis();
 149 }
 150 
 151 void SharkCompiler::compile_method(ciEnv*    env,
 152                                    ciMethod* target,
 153                                    int       entry_bci) {
 154   assert(is_initialized(), "should be");
 155   ResourceMark rm;
 156   const char *name = methodname(
 157     target->holder()->name()->as_utf8(), target->name()->as_utf8());
 158 
 159   // Do the typeflow analysis
 160   ciTypeFlow *flow;
 161   if (entry_bci == InvocationEntryBci)
 162     flow = target->get_flow_analysis();
 163   else
 164     flow = target->get_osr_flow_analysis(entry_bci);
 165   if (flow->failing())
 166     return;
 167   if (SharkPrintTypeflowOf != NULL) {
 168     if (!fnmatch(SharkPrintTypeflowOf, name, 0))
 169       flow->print_on(tty);
 170   }
 171 
 172   // Create the recorders
 173   Arena arena(mtCompiler);
 174   env->set_oop_recorder(new OopRecorder(&arena));
 175   OopMapSet oopmaps;
 176   env->set_debug_info(new DebugInformationRecorder(env->oop_recorder()));
 177   env->debug_info()->set_oopmaps(&oopmaps);
 178   env->set_dependencies(new Dependencies(env));
 179 
 180   // Create the code buffer and builder
 181   CodeBuffer hscb("Shark", 256 * K, 64 * K);
 182   hscb.initialize_oop_recorder(env->oop_recorder());
 183   MacroAssembler *masm = new MacroAssembler(&hscb);
 184   SharkCodeBuffer cb(masm);
 185   SharkBuilder builder(&cb);
 186 
 187   // Emit the entry point
 188   SharkEntry *entry = (SharkEntry *) cb.malloc(sizeof(SharkEntry));
 189 
 190   // Build the LLVM IR for the method
 191   Function *function = SharkFunction::build(env, &builder, flow, name);
 192   if (env->failing()) {
 193     return;


< prev index next >