src/share/vm/c1/c1_Compiler.cpp

Print this page




  25 #include "precompiled.hpp"
  26 #include "c1/c1_Compilation.hpp"
  27 #include "c1/c1_Compiler.hpp"
  28 #include "c1/c1_FrameMap.hpp"
  29 #include "c1/c1_GraphBuilder.hpp"
  30 #include "c1/c1_LinearScan.hpp"
  31 #include "c1/c1_MacroAssembler.hpp"
  32 #include "c1/c1_Runtime1.hpp"
  33 #include "c1/c1_ValueType.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/compilerOracle.hpp"
  36 #include "interpreter/linkResolver.hpp"
  37 #include "memory/allocation.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "prims/nativeLookup.hpp"
  41 #include "runtime/arguments.hpp"
  42 #include "runtime/interfaceSupport.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 
  45 volatile int Compiler::_runtimes = uninitialized;
  46 
  47 Compiler::Compiler() {
  48 }
  49 
  50 
  51 Compiler::~Compiler() {
  52   Unimplemented();
  53 }
  54 
  55 
  56 void Compiler::initialize_all() {
  57   BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
  58   Arena* arena = new (mtCompiler) Arena();
  59   Runtime1::initialize(buffer_blob);
  60   FrameMap::initialize();
  61   // initialize data structures
  62   ValueType::initialize(arena);
  63   // Instruction::initialize();
  64   // BlockBegin::initialize();
  65   GraphBuilder::initialize();
  66   // note: to use more than one instance of LinearScan at a time this function call has to
  67   //       be moved somewhere outside of this constructor:
  68   Interval::initialize(arena);
  69 }
  70 
  71 
  72 void Compiler::initialize() {
  73   if (_runtimes != initialized) {
  74     initialize_runtimes( initialize_all, &_runtimes);











  75   }
  76   mark_initialized();
  77 }
  78 
  79 
  80 BufferBlob* Compiler::get_buffer_blob(ciEnv* env) {
  81   // Allocate buffer blob once at startup since allocation for each
  82   // compilation seems to be too expensive (at least on Intel win32).
  83   BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
  84   if (buffer_blob != NULL) {
  85     return buffer_blob;
  86   }
  87 
  88   // setup CodeBuffer.  Preallocate a BufferBlob of size
  89   // NMethodSizeLimit plus some extra space for constants.
  90   int code_buffer_size = Compilation::desired_max_code_buffer_size() +
  91     Compilation::desired_max_constant_size();
  92 
  93   buffer_blob = BufferBlob::create("Compiler1 temporary CodeBuffer",
  94                                    code_buffer_size);
  95   if (buffer_blob == NULL) {
  96     CompileBroker::handle_full_code_cache();
  97     env->record_failure("CodeCache is full");
  98   } else {
  99     CompilerThread::current()->set_buffer_blob(buffer_blob);
 100   }
 101 
 102   return buffer_blob;
 103 }
 104 
 105 
 106 void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) {
 107   BufferBlob* buffer_blob = Compiler::get_buffer_blob(env);
 108   if (buffer_blob == NULL) {
 109     return;
 110   }
 111 
 112   if (!is_initialized()) {
 113     initialize();
 114   }
 115 
 116   // invoke compilation
 117   {
 118     // We are nested here because we need for the destructor
 119     // of Compilation to occur before we release the any
 120     // competing compiler thread
 121     ResourceMark rm;
 122     Compilation c(this, env, method, entry_bci, buffer_blob);
 123   }
 124 }
 125 
 126 
 127 void Compiler::print_timers() {
 128   Compilation::print_timers();
 129 }


  25 #include "precompiled.hpp"
  26 #include "c1/c1_Compilation.hpp"
  27 #include "c1/c1_Compiler.hpp"
  28 #include "c1/c1_FrameMap.hpp"
  29 #include "c1/c1_GraphBuilder.hpp"
  30 #include "c1/c1_LinearScan.hpp"
  31 #include "c1/c1_MacroAssembler.hpp"
  32 #include "c1/c1_Runtime1.hpp"
  33 #include "c1/c1_ValueType.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "compiler/compilerOracle.hpp"
  36 #include "interpreter/linkResolver.hpp"
  37 #include "memory/allocation.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "prims/nativeLookup.hpp"
  41 #include "runtime/arguments.hpp"
  42 #include "runtime/interfaceSupport.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 


  45 Compiler::Compiler() {
  46 }
  47 
  48 
  49 Compiler::~Compiler() {
  50   Unimplemented();
  51 }
  52 
  53 
  54 void Compiler::init_c1_runtime() {
  55   BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
  56   Arena* arena = new (mtCompiler) Arena();
  57   Runtime1::initialize(buffer_blob);
  58   FrameMap::initialize();
  59   // initialize data structures
  60   ValueType::initialize(arena);


  61   GraphBuilder::initialize();
  62   // note: to use more than one instance of LinearScan at a time this function call has to
  63   //       be moved somewhere outside of this constructor:
  64   Interval::initialize(arena);
  65 }
  66 
  67 
  68 void Compiler::initialize() {
  69   // Buffer blob must be allocated per C1 compiler thread at startup
  70   BufferBlob* buffer_blob = init_buffer_blob();
  71   if (buffer_blob == NULL) {
  72     // If the state is initialized, other compiler threads could have
  73     // had enough space to allocate memory
  74     if (!is_initialized()) {
  75       set_state(failed);
  76     }
  77   }
  78 
  79   if (should_perform_init()) {
  80     init_c1_runtime();
  81     set_state(initialized);
  82   }

  83 }
  84 
  85 
  86 BufferBlob* Compiler::init_buffer_blob() {
  87   // Allocate buffer blob once at startup since allocation for each
  88   // compilation seems to be too expensive (at least on Intel win32).
  89   assert (CompilerThread::current()->get_buffer_blob() == NULL, "Should initialize only once");



  90 
  91   // setup CodeBuffer.  Preallocate a BufferBlob of size
  92   // NMethodSizeLimit plus some extra space for constants.
  93   int code_buffer_size = Compilation::desired_max_code_buffer_size() +
  94     Compilation::desired_max_constant_size();
  95 
  96   BufferBlob* buffer_blob = BufferBlob::create("C1 temporary CodeBuffer", code_buffer_size);
  97   if (buffer_blob != NULL) {




  98     CompilerThread::current()->set_buffer_blob(buffer_blob);
  99   }
 100 
 101   return buffer_blob;
 102 }
 103 
 104 
 105 void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) {
 106   BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
 107   assert(buffer_blob != NULL, "Must exist");







 108   // invoke compilation
 109   {
 110     // We are nested here because we need for the destructor
 111     // of Compilation to occur before we release the any
 112     // competing compiler thread
 113     ResourceMark rm;
 114     Compilation c(this, env, method, entry_bci, buffer_blob);
 115   }
 116 }
 117 
 118 
 119 void Compiler::print_timers() {
 120   Compilation::print_timers();
 121 }