changeset 10540:0ba44a5a8420

Add sanity check to avoid overwriting the reserved code buffer for very large methods.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 26 Jun 2013 15:22:11 +0200
parents 5d460d3465fd
children 9599e1a01812
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalCodeInstaller.hpp src/share/vm/graal/graalEnv.hpp
diffstat 4 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Wed Jun 26 15:17:17 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Wed Jun 26 15:22:11 2013 +0200
@@ -144,7 +144,7 @@
 
     // Must be kept in sync with enum in graalEnv.hpp
     public enum CodeInstallResult {
-        OK, DEPENDENCIES_FAILED, CACHE_FULL
+        OK, DEPENDENCIES_FAILED, CACHE_FULL, CODE_TOO_LARGE
     }
 
     /**
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Wed Jun 26 15:17:17 2013 +0200
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Wed Jun 26 15:22:11 2013 +0200
@@ -369,7 +369,10 @@
   {
     No_Safepoint_Verifier no_safepoint;
     initialize_fields(JNIHandles::resolve(compiled_code_obj));
-    initialize_buffer(buffer);
+    if (!initialize_buffer(buffer)) {
+      result = GraalEnv::code_too_large;
+      return;
+    }
     process_exception_handlers();
   }
 
@@ -427,7 +430,7 @@
 }
 
 // perform data and call relocation on the CodeBuffer
-void CodeInstaller::initialize_buffer(CodeBuffer& buffer) {
+bool CodeInstaller::initialize_buffer(CodeBuffer& buffer) {
   int locs_buffer_size = _sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
   char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size);
   buffer.insts()->initialize_shared_locs((relocInfo*)locs_buffer, locs_buffer_size / sizeof(relocInfo));
@@ -443,8 +446,12 @@
   _constants = buffer.consts();
 
   // copy the code into the newly created CodeBuffer
+  address end_pc = _instructions->start() + _code_size;
+  if (!_instructions->allocates2(end_pc)) {
+    return false;
+  }
   memcpy(_instructions->start(), _code->base(T_BYTE), _code_size);
-  _instructions->set_end(_instructions->start() + _code_size);
+  _instructions->set_end(end_pc);
 
   for (int i = 0; i < _sites->length(); i++) {
     oop site=((objArrayOop) (_sites))->obj_at(i);
@@ -486,6 +493,7 @@
     }
   }
 #endif
+  return true;
 }
 
 void CodeInstaller::assumption_MethodContents(Handle assumption) {
--- a/src/share/vm/graal/graalCodeInstaller.hpp	Wed Jun 26 15:17:17 2013 +0200
+++ b/src/share/vm/graal/graalCodeInstaller.hpp	Wed Jun 26 15:22:11 2013 +0200
@@ -94,7 +94,7 @@
   void initialize_assumptions(oop target_method);
 
   // perform data and call relocation on the CodeBuffer
-  void initialize_buffer(CodeBuffer& buffer);
+  bool initialize_buffer(CodeBuffer& buffer);
 
   void assumption_MethodContents(Handle assumption);
   void assumption_NoFinalizableSubclass(Handle assumption);
--- a/src/share/vm/graal/graalEnv.hpp	Wed Jun 26 15:17:17 2013 +0200
+++ b/src/share/vm/graal/graalEnv.hpp	Wed Jun 26 15:22:11 2013 +0200
@@ -62,7 +62,8 @@
   enum CodeInstallResult {
      ok,
      dependencies_failed,
-     cache_full
+     cache_full,
+     code_too_large
   };
 
   // Look up a klass by name from a particular class loader (the accessor's).