changeset 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 1dd9aa5a9ee5
children 680060a794a1
files src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalCompiler.cpp src/share/vm/graal/graalCompiler.hpp
diffstat 3 files changed, 26 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Mon Nov 25 17:23:56 2013 +0100
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Mon Nov 25 15:10:04 2013 -0800
@@ -361,8 +361,13 @@
 
 // constructor used to create a method
 CodeInstaller::CodeInstaller(Handle& compiled_code, GraalEnv::CodeInstallResult& result, CodeBlob*& cb, Handle installed_code, Handle triggered_deoptimizations) {
-  GraalCompiler::initialize_buffer_blob();
-  CodeBuffer buffer(JavaThread::current()->get_buffer_blob());
+  BufferBlob* buffer_blob = GraalCompiler::initialize_buffer_blob();
+  if (buffer_blob == NULL) {
+    result = GraalEnv::cache_full;
+    return;
+  }
+
+  CodeBuffer buffer(buffer_blob);
   jobject compiled_code_obj = JNIHandles::make_local(compiled_code());
   initialize_assumptions(JNIHandles::resolve(compiled_code_obj));
 
--- 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) {
--- a/src/share/vm/graal/graalCompiler.hpp	Mon Nov 25 17:23:56 2013 +0100
+++ b/src/share/vm/graal/graalCompiler.hpp	Mon Nov 25 15:10:04 2013 -0800
@@ -105,7 +105,7 @@
     return cp_index;
   }
 
-  static void initialize_buffer_blob();
+  static BufferBlob* initialize_buffer_blob();
 };
 
 // Tracing macros