hotspot/src/share/vm/c1/c1_Compiler.cpp
changeset 20707 b3b658c6d1f8
parent 17623 6295813086d0
child 22234 da823d78ad65
--- a/hotspot/src/share/vm/c1/c1_Compiler.cpp	Fri Oct 11 10:14:02 2013 -0700
+++ b/hotspot/src/share/vm/c1/c1_Compiler.cpp	Thu Oct 10 15:44:12 2013 +0200
@@ -42,26 +42,16 @@
 #include "runtime/interfaceSupport.hpp"
 #include "runtime/sharedRuntime.hpp"
 
-volatile int Compiler::_runtimes = uninitialized;
-
-Compiler::Compiler() {
-}
-
 
-Compiler::~Compiler() {
-  Unimplemented();
-}
+Compiler::Compiler () {}
 
-
-void Compiler::initialize_all() {
+void Compiler::init_c1_runtime() {
   BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
   Arena* arena = new (mtCompiler) Arena();
   Runtime1::initialize(buffer_blob);
   FrameMap::initialize();
   // initialize data structures
   ValueType::initialize(arena);
-  // Instruction::initialize();
-  // BlockBegin::initialize();
   GraphBuilder::initialize();
   // note: to use more than one instance of LinearScan at a time this function call has to
   //       be moved somewhere outside of this constructor:
@@ -70,32 +60,33 @@
 
 
 void Compiler::initialize() {
-  if (_runtimes != initialized) {
-    initialize_runtimes( initialize_all, &_runtimes);
+  // Buffer blob must be allocated per C1 compiler thread at startup
+  BufferBlob* buffer_blob = init_buffer_blob();
+
+  if (should_perform_init()) {
+    if (buffer_blob == NULL) {
+      // When we come here we are in state 'initializing'; entire C1 compilation
+      // can be shut down.
+      set_state(failed);
+    } else {
+      init_c1_runtime();
+      set_state(initialized);
+    }
   }
-  mark_initialized();
 }
 
-
-BufferBlob* Compiler::get_buffer_blob(ciEnv* env) {
+BufferBlob* Compiler::init_buffer_blob() {
   // Allocate buffer blob once at startup since allocation for each
   // compilation seems to be too expensive (at least on Intel win32).
-  BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
-  if (buffer_blob != NULL) {
-    return buffer_blob;
-  }
+  assert (CompilerThread::current()->get_buffer_blob() == NULL, "Should initialize only once");
 
   // setup CodeBuffer.  Preallocate a BufferBlob of size
   // NMethodSizeLimit plus some extra space for constants.
   int code_buffer_size = Compilation::desired_max_code_buffer_size() +
     Compilation::desired_max_constant_size();
 
-  buffer_blob = BufferBlob::create("Compiler1 temporary CodeBuffer",
-                                   code_buffer_size);
-  if (buffer_blob == NULL) {
-    CompileBroker::handle_full_code_cache();
-    env->record_failure("CodeCache is full");
-  } else {
+  BufferBlob* buffer_blob = BufferBlob::create("C1 temporary CodeBuffer", code_buffer_size);
+  if (buffer_blob != NULL) {
     CompilerThread::current()->set_buffer_blob(buffer_blob);
   }
 
@@ -104,15 +95,8 @@
 
 
 void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci) {
-  BufferBlob* buffer_blob = Compiler::get_buffer_blob(env);
-  if (buffer_blob == NULL) {
-    return;
-  }
-
-  if (!is_initialized()) {
-    initialize();
-  }
-
+  BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
+  assert(buffer_blob != NULL, "Must exist");
   // invoke compilation
   {
     // We are nested here because we need for the destructor