diff src/share/vm/graal/graalCompiler.cpp @ 13156:2e76d94f8383

propagate code-cache-full message up to Java to throw exception instead of crashing VM
author twisti
date Mon, 25 Nov 2013 15:10:04 -0800
parents bdc836ef885e
children f13f6dc290c8
line wrap: on
line diff
--- a/src/share/vm/graal/graalCompiler.cpp	Mon Nov 25 17:23:56 2013 +0100
+++ b/src/share/vm/graal/graalCompiler.cpp	Mon Nov 25 15:10:04 2013 -0800
@@ -56,7 +56,13 @@
 
   _deopted_leaf_graph_count = 0;
 
-  initialize_buffer_blob();
+  BufferBlob* buffer_blob = initialize_buffer_blob();
+  if (buffer_blob == NULL) {
+    // If we are called from JNI_CreateJavaVM we cannot use set_state yet because it takes a lock.
+    // set_state(failed);
+  } else {
+    // set_state(initialized);
+  }
 
   JNIEnv *env = ((JavaThread *) Thread::current())->jni_environment();
   jclass klass = env->FindClass("com/oracle/graal/hotspot/bridge/CompilerToVMImpl");
@@ -106,10 +112,12 @@
       _initialized = true;
       CompilationPolicy::completed_vm_startup();
       if (bootstrap) {
+        // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping.
+        FlagSetting a(UseInterpreter, true);
+        FlagSetting b(BackgroundCompilation, true);
         VMToCompiler::bootstrap();
       }
 
-
 #ifndef PRODUCT
       if (CompileTheWorld) {
         // We turn off CompileTheWorld so that Graal can
@@ -163,14 +171,16 @@
   return array;
 }
 
-void GraalCompiler::initialize_buffer_blob() {
-
+BufferBlob* GraalCompiler::initialize_buffer_blob() {
   JavaThread* THREAD = JavaThread::current();
-  if (THREAD->get_buffer_blob() == NULL) {
-    BufferBlob* blob = BufferBlob::create("Graal thread-local CodeBuffer", GraalNMethodSizeLimit);
-    guarantee(blob != NULL, "must create code buffer");
-    THREAD->set_buffer_blob(blob);
+  BufferBlob* buffer_blob = THREAD->get_buffer_blob();
+  if (buffer_blob == NULL) {
+    buffer_blob = BufferBlob::create("Graal thread-local CodeBuffer", GraalNMethodSizeLimit);
+    if (buffer_blob != NULL) {
+      THREAD->set_buffer_blob(buffer_blob);
+    }
   }
+  return buffer_blob;
 }
 
 void GraalCompiler::compile_method(methodHandle method, int entry_bci, jboolean blocking) {